跨多文件的 Typescript 命名空间

zer*_*4wl 5 typescript typescript2.0

我尝试在单个命名空间但在多个文件中编写打字稿代码。config但是当我在类中使用该类时AAAConfig未定义并且存在语法错误。为什么?

检查这个例子:

file: services/Config/index.ts

export namespace Services {
    export class Config {
      /* class methods */
    }
}
Run Code Online (Sandbox Code Playgroud)

file: services/AAA/index.ts

/// <reference path = "./../Config/index.ts" />
export namespace Service {
    export class AAAA {
      private config = new Config(); <-- Error is here
      /* class methods */
    }
}
Run Code Online (Sandbox Code Playgroud)

Cle*_*ton 1

您不导出名称空间:

namespace Services {
 export class Config {
  /* class methods */
 }
}

/// <reference path = "../Config/index.ts"/> 
namespace Service {
 export class AAAA {
  private config = new Config(); <-- Error is here
  /* class methods */
 }
}
Run Code Online (Sandbox Code Playgroud)

https://www.typescriptlang.org/docs/handbook/namespaces.html