TypeScript 和 ng2 rc.1 出现错误:(20, 15) TS2304:找不到名称“模块”。
当尝试使用模块指令时
@Component({
selector: 'Notes1',
moduleId: module.id,
directives: [ModalDialog, FORM_DIRECTIVES, DisplayError],
templateUrl: 'Notes1.html',
styleUrls: ['Notes1.css']
})
知道如何修复 TS 错误.. 在运行时一切正常
问候
肖恩
最佳答案
错误意味着 TypeScript 编译器不知道 module
是什么。快速修复:
declare var require: any;
为了使其更完整,请使用 DefinitelyTyped/node 中的定义:
interface NodeRequireFunction {
(id: string): any;
}
interface NodeRequire extends NodeRequireFunction {
resolve(id:string): string;
cache: any;
extensions: any;
main: any;
}
declare var require: NodeRequire;
interface NodeModule {
exports: any;
require: NodeRequireFunction;
id: string;
filename: string;
loaded: boolean;
parent: any;
children: any[];
}
declare var module: NodeModule;
关于TypeScript 和 ng2 rc.1 出现错误 :(20, 15) TS2304:找不到名称 'module',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37093297/