我一直在测试打字稿与节点,一切进行得很顺利,直到我试图分裂出来这些。
我是被迫使用模块?
我有2个文件,其中有一个参考路径hellofile.tst app.ts
/// <reference path="hellofile.ts" />
var testme = new Hello()
console.log(testme.testMe());
和包含hellofile.ts
class Hello {
testMe():string {
return "hello";
}
}
现在运行的程序(我使用webstorm),我收到以下错误。
/usr/local/bin/node app.js
/
Users/tst/WebstormProjects/NodeJsWithTypescript/app.js:2
var testme = new Hello();
^
ReferenceError: Hello is not defined
at Object.<anonymous> (/Users/tst/WebstormProjects/NodeJsWithTypescript/app.js:2:18)
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 Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
Process finished with exit code 8
您不必使用模块。你可以用--out标志编译
但随着CommonJS的外部模块,强烈建议,如果瞄准的NodeJS:http://m.youtube.com/watch?v=KDrWLMUY0R0