How do I use namespaces with TypeScript external modules?

前端 未结 9 1430
陌清茗
陌清茗 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:38

    Small impovement of Albinofrenchy answer:

    base.ts

    export class Animal {
    move() { /* ... */ }
    }
    
    export class Plant {
      photosynthesize() { /* ... */ }
    }
    

    dog.ts

    import * as b from './base';
    
    export class Dog extends b.Animal {
       woof() { }
    } 
    

    things.ts

    import { Dog } from './dog'
    
    namespace things {
      export const dog = Dog;
    }
    
    export = things;
    

    main.ts

    import * as things from './things';
    
    console.log(things.dog);
    

提交回复
热议问题