命名空间和模块最好不要混用,即不要在一个模块中使用命名空间,最好在一个全局的环境使用.
    在早期版本中,命名空间就是内部模块,本质上是闭包,用于隔离作用域。

    1. namespace Shape {
    2. const pi = Math.PI
    3. export function cricle(r: number) {
    4. return pi * r ** 2
    5. }
    6. }
    7. /// <reference path="a.ts" />
    8. // 防止引用a.ts报错
    9. namespace Shape {
    10. export function square(x: number) {
    11. return x * x
    12. }
    13. }
    14. console.log(Shape.cricle(1))
    15. console.log(Shape.square(1))
    16. // 命名空间的别名
    17. import cricle = Shape.cricle
    18. console.log(cricle(2))