What's the correct way to use requireJS with typescript?

前端 未结 4 2027
闹比i
闹比i 2020-12-25 11:29

The examples I have found here and here say to use module(). However, when I compile I get \"warning TS7021: \'module(...)\' is deprecated. Use \'require(...)\' instead.\"

4条回答
  •  长发绾君心
    2020-12-25 11:44

    You want the export statement below the class you are creating.

    // Base.ts
    class Base {
    
        constructor() {
        }
    
        public createChildren():void {
    
        }
    }
    
    export = Base;
    

    Then to import and use into another class you would do:

    // TestApp.ts
    import Base = require("view/Base");
    
    class TestApp extends Base {
    
        private _title:string = 'TypeScript AMD Boilerplate';
    
        constructor() {
            super();
        }
    
        public createChildren():void {
    
        }
    }
    
    export = TestApp;
    

提交回复
热议问题