我有一个用打字稿编写的有角度的项目。这在 VS 下对我来说效果很好,现在我在 webstorm 下尝试使用 Node.JS 进行同样的操作。
我在progressor.ts 文件中有一个progressor 类:
export class Progressor{
public tasks: any;
constructor(){
this.tasks = {};
}
...
}
我有我的主控制器,它使用这个类:
/// <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();
// ...
}
};
}
请注意,这不是 Node.JS 代码 - 它只是 Node.JS 项目的一部分。
相对参考路径正确。当我尝试使用以下命令编译它时:
tsc mainController.ts --module amd --target es5
我收到错误:找不到名称 Progressor。
我不明白问题出在哪里...到目前为止,我的 Node.JS 项目一直遇到麻烦,我正在考虑为这个项目完全放弃 TS。首先 - 谁能告诉我为什么它不能编译?请注意,我希望每个 TS 文件单独编译,这样我就可以通过 Chrome 轻松调试它们。
如果你有export
编辑了一些东西,你需要import
为了消费它,而不是<reference ...
it.
更换<reference
评论与import prog = require('./progressor');
,那么你可以使用例如new prog.Progressor()
.
您可能会考虑使用export = Progressor
以便从其他文件导出的对象是类本身而不是容器。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)