Preventing tsc compiler from omitting the unnecessary external modules

后端 未结 2 919
谎友^
谎友^ 2021-01-16 05:25

There\'s a feature in TypeScript which I like so much and that\'s external modules using RequireJs and that the fact that the compiler won\'t include imported modules unless

相关标签:
2条回答
  • 2021-01-16 06:13

    There is a simply fiddle you can do to get the compiler to include both:

    import A = require('./A');
    import B = require('./B');
    
    var a = new A();
    var b = B;
    

    The variable b becomes noise in your program, so I wouldn't use this technique too much, but if the B module is doing polyfills or something like that which means you'll never want to directly instantiate it, this gets it loaded for you.

    0 讨论(0)
  • 2021-01-16 06:15

    Another way to do it:

    /// <amd-dependency path="./B" />
    import A = require('./A');
    

    No need to create fictitious code

    0 讨论(0)
提交回复
热议问题