Multiple files making up Type Script project

后端 未结 3 1200
不知归路
不知归路 2020-12-31 00:15

Recently I have been working with TypeScript and everything has been fine and I really, really like it.. Makes JavaScript workable again! :)

we have tried to follow

3条回答
  •  无人及你
    2020-12-31 00:55

    I wrote about getting the right set up for TypeScript and one of the ideas in there will help you - I originally got the idea from Mark Rendle.

    The idea is that create a file named references.ts and have all of your dependencies listed in there. A bit like this:

    /// 
    /// 
    /// 
    /// 
    /// 
    

    You can then simply reference this file at the top of all your TypeScript files:

    /// 
    module ModuleA {
        export class MyClass {
            doSomething() {
                return 'Hello';
            }
            tester() {
                var x = new ModuleB.MyClass();
            }
        }
    }
    

    The references.ts file acts like the References folder you have for a .NET project.

    The other recommendation, which works quite well with this set up, is to use the --out flag to compile a single JavaScript file, starting with app.ts. The TypeScript compiler walks all the dependencies and works out the correct order for all the generated JavaScript.

    tsc --out final.js app.ts
    

    This strategy will scale with your program much better than manually referencing specific files everywhere.

提交回复
热议问题