阅读this manual后和这句话的区别:之间有什么`声明namespace`和`声明module`
需要注意的是,在打字稿1.5是很重要的,命名了 改变。 “内部模块”现在是“命名空间”。 “外部模块” 现在只是“模块”
我下的印象是不再使用declare module
,由declare namespace
取代,然而探索node_modules\@types\node\index.d.ts
时,我可以看到,无论declare module
和declare namespace
用于:
declare namespace NodeJS {
export var Console: {
prototype: Console;
new(stdout: WritableStream, stderr?: WritableStream): Console;
}
...
declare module "buffer" {
export var INSPECT_MAX_BYTES: number;
var BuffType: typeof Buffer;
var SlowBuffType: typeof SlowBuffer;
export { BuffType as Buffer, SlowBuffType as SlowBuffer };
}
为什么这么说?有什么不同?
外部模块(ES6模块)不要求在这里发挥作用,据我了解。
对于您在帖子中的链接中的两个段落,都有一个简短的定义。基本上命名空间是Typescripts实现模块模式的方式。虽然模块现在与ES2015模块相同。声明部分意味着两者都预计会出现并由其他人定义。 :) – toskv
@toskv,是的,我肯定读过我链接到的页面。但它很混乱,这就是为什么我在这里发布问题 –
@toskv,我有正确的答案,请参阅[我的答案](http://stackoverflow.com/a/42030656/2545680) –