gpt4 book ai didi

javascript - Typescript 1.6 命名空间和导入类 (commonJS)

转载 作者:行者123 更新时间:2023-12-03 08:28:12 25 4
gpt4 key购买 nike

我尝试在 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;
}

}

接口(interface)接缝将按预期共享。但是 CoreConfigApp 类在 core.config.ts 文件中抛出错误。

tsconfig:

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

我在代码中错过了什么,我的类也可以在同一命名空间中的其他文件上访问?引用路径定义没有帮助。非常感谢您的提示!

最佳答案

reference path definitions didn't help. thank you very much for hints!

out/outFile 有问题 documented here这可能会导致它在运行时失败。请不要使用命名空间仅使用 commonjs 模块

关于javascript - Typescript 1.6 命名空间和导入类 (commonJS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33457205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com