简体   繁体   English

Typescript 1.6名称空间和导入类(commonJS)

[英]Typescript 1.6 namespaces and import classes (commonJS)

I try to use namespaces on TS 1.6 with multiple files on the same NS. 我尝试将TS 1.6上的命名空间与同一个NS上的多个文件一起使用。

 --------------------------------------------------- app/core/config/core.config.ts --------------------------------------------------- namespace app.core.config { export class CoreConfig { public appConfig : CoreConfigApp; constructor() { // Uncaught TypeError: config.CoreConfigApp is not a function this.appConfig = new CoreConfigApp().getDevelopment(); } } } --------------------------------------------------- app/core/config/core.config.app.ts --------------------------------------------------- namespace app.core.config { export class CoreConfigApp implements ICoreConfig { public name : string; public version : string; constructor() { this.name = 'super app'; this.version = '1.0.0-alpha'; } getDevelopment() { return this; } getProduction() { return this; } } } --------------------------------------------------- app/core/config/core.config.interfaces.ts --------------------------------------------------- namespace app.core.config { export interface ICoreConfig { getDevelopment() : any; getProduction() : any; } } 

The interface seams to be shared as expected. 接口接缝将按预期方式共享。 But the CoreConfigApp class throws a error in core.config.ts file. 但是CoreConfigApp类在core.config.ts文件中引发错误。

tsconfig: tsconfig:

 { "compilerOptions": { "module": "commonjs", "sourceMap": true, "target": "es5", "experimentalDecorators": true }, "exclude": [ "bower_components", "node_modules" ] } 

What do I miss in the code, that my class is also accessable on other files in the same namespace? 在代码中我想念的是,我的类也可以在相同名称空间中的其他文件上访问吗? reference path definitions didn't help. 参考路径定义没有帮助。 thank you very much for hints! 非常感谢您的提示!

reference path definitions didn't help. 参考路径定义没有帮助。 thank you very much for hints! 非常感谢您的提示!

out / outFile has issues documented here that can cause it to fail at runtime. out / outFile具有此处记录的问题,可能会导致它在运行时失败。 Please don't use namespaces and just use commonjs modules . 请不要使用namespaces而应使用commonjs模块

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM