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



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

接口接缝应按预期进行共享。但是CoreConfigApp类在core.config.ts文件中抛出错误。

tsconfig:

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

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

引用路径定义没有帮助。非常感谢你的提示!

out/outFile在这里记录了一些问题,这些问题可能会导致它在运行时失败。请不要使用namespaces,只使用commonjs模块

最新更新