TypeScript 中的命名空间关键字

Namespace keyword in TypeScript

试图找出 namespace 关键字在 TypeScript 中的含义?

这是他们最近使用 namespace 而不是 module 进行的一些重组:

https://github.com/Microsoft/TypeScript/commit/224e7630ea17c4547e97f85634f446b877955a67

在没有命名空间规范的情况下,使语言看起来像 C# 的重命名似乎毫无意义。

或者两者之间有什么微妙的区别? namespace 一词表示使用相同名称的多个声明之间共享 scope/space。这是一个正确的直觉吗?

您可以在 namespace keyword 问题中阅读它,但基本思想是区分内部 (namespace) 和外部 (module) 模块。

To better align with ES6 modules as suggested in #2159, this PR introduces a new namespace keyword as the preferred way to declare what was formerly known as "internal modules". Our terminology changes as follows:

  • Internal module becomes Namespace.
  • External module becomes Module.

For backwards compatibility, namespaces can still be declared in the old way (using the module keyword) and no existing code is broken by this change. We may consider introducing a compiler option that disallows using the module keyword to declare namespaces.

Source