Does TypeScript support namespace?

后端 未结 5 974
无人共我
无人共我 2021-02-02 05:47

As in the title: does TypeScript support namespaces? If so, how do I use them?

5条回答
  •  面向向阳花
    2021-02-02 06:13

    False...

    module A.B.C {
        export var x = 1;
    }
    

    is equal to

    module A {
        export module B {
            export module C {
                export var x = 1;
            }
        }
    }
    

    because you can write outside the module A :

    var y = A.B.C.x;
    

    But :

    module A {
        module B {
            module C {
                export var x = 1;
            }
            var y = C.x; // OK
        }
        //var y = B.C.x; // Invalid
    }
    //var y = A.B.C.x;   // Invalid
    

提交回复
热议问题