我有一个角色项目,我用打字稿写.这在VS下很适合我,现在我在webstorm下尝试使用Node.JS.
我在progressor.ts文件中有一个进度类:
export class Progressor{
public tasks: any;
constructor(){
this.tasks = {};
}
...
}
Run Code Online (Sandbox Code Playgroud)
我有我的主控制器,它使用这个类:
/// <reference path="../progressor.ts" />
declare var angular: any; // I'm trying to eliminate these...
declare var Papa: any;
declare var $: any;
class MainController{
constructor($scope: any){
$scope.progressor = null;
$scope.filesDropped = function(files, rejectedFiles){
if(!files || !files.length)
return;
$scope.progressor = new Progressor();
// ...
}
};
}
Run Code Online (Sandbox Code Playgroud)
请注意,这不是Node.JS代码 - 它只是Node.JS项目的一部分.
相对参考路径是正确的.当我尝试使用以下方法编译它时:
tsc mainController.ts --module amd --target es5
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:找不到名称Progressor.
我不明白是什么问题......到目前为止,我的Node.JS项目一直没有问题,而且我正在考虑完全放弃TS用于这个项目.首先 - 任何人都可以告诉我为什么它不会编译?请注意,我希望每个TS文件都单独编译,因此我可以通过Chrome轻松调试它们.
Rya*_*ugh 10
如果你已经做过export某些事情,你需要import它来消费它,而不是<reference ...它.
替换<reference注释import prog = require('./progressor');,然后您可以使用例如new prog.Progressor().
您可以考虑使用,export = Progressor以便从另一个文件导出的对象是类本身而不是容器.
经过一段时间的搜索,我偶然发现了这个:TypeScript Modules。在咨询之后,我尝试将我的两个类都放在 module{ } 块中,从而解决了问题。我仍然对为什么该语言要求我使用模块进行多文件使用感到有些困惑……但现在它会这样做。
| 归档时间: |
|
| 查看次数: |
55496 次 |
| 最近记录: |