How do you put multiple external modules into the same namespace in TypeScript?

前端 未结 3 2033
误落风尘
误落风尘 2020-12-28 16:40

Say I want to have one class per .ts file. I have two .ts files, that look like so:

export module MyClasses { export class A {} }

and

3条回答
  •  清歌不尽
    2020-12-28 17:07

    Excuse the poor variable names, I was testing this in Visual Studio. It worked for my when using different names for the import statements.

    import x = module('A');
    import y = module('B');
    
    x.MyClasses.A;
    y.MyClasses.B;
    

    Alternatively, you can use reference comments to a similar effect, but this is better if you are bundling, not if you are using module loading. You would need to drop the export keyword from your two MyClasses declarations:

    ///
    ///
    
    var x = MyClasses.A;
    

提交回复
热议问题