How do I use namespaces with TypeScript external modules?

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

I have some code:

baseTypes.ts

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


        
9条回答
  •  -上瘾入骨i
    2020-11-22 09:35

    Try this namespaces module

    namespaceModuleFile.ts

    export namespace Bookname{
    export class Snows{
        name:any;
        constructor(bookname){
            console.log(bookname);
        }
    }
    export class Adventure{
        name:any;
        constructor(bookname){
            console.log(bookname);
        }
    }
    }
    
    
    
    
    
    export namespace TreeList{
    export class MangoTree{
        name:any;
        constructor(treeName){
            console.log(treeName);
        }
    }
    export class GuvavaTree{
        name:any;
        constructor(treeName){
            console.log(treeName);
        }
    }
    }
    

    bookTreeCombine.ts

    ---compilation part---

    import {Bookname , TreeList} from './namespaceModule';
    import b = require('./namespaceModule');
    let BooknameLists = new Bookname.Adventure('Pirate treasure');
    BooknameLists = new Bookname.Snows('ways to write a book'); 
    const TreeLis = new TreeList.MangoTree('trees present in nature');
    const TreeLists = new TreeList.GuvavaTree('trees are the celebraties');
    

提交回复
热议问题