如何在文件之间使用命名空间?

How to use namespaces between files?

我正在使用 TypeScript 1.6.2 和 atom-typescript。尝试在单独的文件上使用命名空间:

// Main.ts
import * as _ from 'lodash'
namespace Test
{
  export var value = true
}

// Another.ts
namespace Another
{
  function Testing()
  {
    return Test.value == true
  }
}

我尝试使用引用,但仍然没有用,还有一个有效的 tsconfig.json 并且它的设置是为了解决包含定义和文件的问题:

{
"compilerOptions": {
    "noEmit": true
},
"compileOnSave": false,
"filesGlob": [
    "./**/*.ts",
    "./Scripts/typings/**/*.d.ts",
    "!./node_modules/**/*.ts"
],
"files": [
    "./Scripts/typings/tsd.d.ts"
]
}

因为您有 `import * as _ from 'lodash',这使得文件 成为一个单独的模块 https://basarat.gitbooks.io/typescript/content/docs/project/modules.html

如果您正在使用模块...请不要使用名称空间,因为它只是一个不必要的间接点。每个文件的变量(包括名称空间)都与其他文件不同。