TypeScript 和 ng2 rc.1 出现错误 :(20, 15) TS2304:找不到名称 'module'

标签 typescript angular

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/

相关文章:

node.js - Angular 2 实时刷新应用

html - 如何取消选中 Angular 7 中单击按钮时的复选框

javascript - 在 Angular 2 中获取数组的副本而不影响原始数组

Angular - 在路由器事件中获取组件实例

html - 从数组 typescript 中删除对象(Angular 2)

javascript - 强制函数仅接受特定结构的对象(在 typescript/js 中)

typescript - 相似类型约束和条件类型的区别

angular - Angular辅助路由懒加载时报错: Cannot match any routes.

javascript - 用于文件上传的 Angular2 服务器端监听器

angular - 如何在 docker env 中使用 nginx 反向代理来通信 UI 和后端应用程序