1
我正在使用TypeScript 1.6.2和atom-typingcript。尝试使用在不同的文件命名空间:如何在文件之间使用命名空间?
// 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"
]
}
谢谢Basarat!但是我不能利用名称空间来不需要相对路径吗?像''从'../../../../ Service.ts''导入{something}我以为我可以使用命名空间来让编译器解析文件的位置...... – Hadrian
不幸的是,目前尚不支持。它的一个负担留在其他*构建工具像webpack *或*运行时像nodejs * – basarat
所以最好的选择是等待1.8和[在模块分辨率中使用路径映射](https://github.com/Microsoft/TypeScript/问题/ 5039) – Hadrian