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

标签 javascript module typescript

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

相关文章:

javascript - JQuery 错误事件在错误时加载备用图像

javascript - 从对象内函数数组中的回调函数访问正确的 "this"

python - 你能迭代导入 python 模块吗?

javascript - 为什么 CssMinimizerWebpackPlugin 会阻止我的主 js 文件被缩小?

子进程中模块的Python调用函数

python - 如何在Python模块初始化时启用日志记录?

reactjs - 如何将 Chessboard.js 与 Reactjs 一起使用?

javascript - 使用字符串数组作为路径动态访问嵌套对象

javascript - Angular2可点击表格行,最后一个单元格除外

javascript - AngularJS 在 Promise 调用后显示应用程序的不同状态