NTVS = Visual Studio 的节点工具
我创建了一个以 server.js 作为主文件的新项目。然后创建了几个类,每个类都在他们的文件中。所有这些文件都在references.ts 文件中引用。
所有文件都包含对references.ts 的引用。
但是,我的项目没有运行。它说某些类不存在。
所以我勾选了“将 Javascript 输出合并到文件中”,但 server.ts 中的代码没有附加到结果文件中(所有类都很难)。
我怎么能使用内部引用?
编辑:这是我使用的文件
服务器.ts
/// <reference path="references.ts"/>
import http = require('http');
var html = new HtmlElement('html');
...
类/HtmlElement.ts
class HtmlElement {
tag: string;
attributes: Array<HtmlAttribute>;
childrens: Array<HtmlElement>;
parent: HtmlElement;
text: string;
...
参考文献.ts
/// <reference path="Scripts/typings/node/node.d.ts" />
/// <reference path="Classes/HtmlElement.ts" />
如果编译时没有 combine 选项,这是 node.js window 的输出:
debugger listening on port 5858
C:\Zdisk\Projets\14 08 - QCM\NodeJsTypeScript1\ServerApp\server.js:5
var html = new HtmlElement('html');
^
ReferenceError: HtmlElement is not defined
at Object.<anonymous (C:\Projects\NodeJsTypeScript1\Server
App\server.js:5:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain [as _onTimeout] (module.js:497:10)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
Press any key to continue...
如果我使用 combine 选项,则不会发生任何事情,因为生成的文件仅包含类声明。