How do I use namespaces with TypeScript external modules?

前端 未结 9 1428
陌清茗
陌清茗 2020-11-22 08:59

I have some code:

baseTypes.ts

export namespace Living.Things {
  export class Animal {
    move() { /* ... */ }
  }
  export class          


        
9条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 09:31

    dog.ts

    import b = require('./baseTypes');
    
    export module Living.Things {
        // Error, can't find name 'Animal', ??
        // Solved: can find, if properly referenced; exporting modules is useless, anyhow
        export class Dog extends b.Living.Things.Animal {
            public woof(): void {
                return;
            }
        }
    }
    

    tree.ts

    // Error, can't use the same name twice, ??
    // Solved: cannot declare let or const variable twice in same scope either: just use a different name
    import b = require('./baseTypes');
    import d = require('./dog');
    
    module Living.Things {
        // Why do I have to write b.Living.Things.Plant instead of b.Plant??
        class Tree extends b.Living.Things.Plant {
        }
    }
    

提交回复
热议问题