代码之家  ›  专栏  ›  技术社区  ›  Emilio Platzer

如何在TypeScript中内联导入另一个源

  •  2
  • Emilio Platzer  · 技术社区  · 6 年前

    class MyClass{
        data(){
            return [
                require('this-module'),
                require('another-module),
                require('that-module),
            ];
        }
    }
    

    在Typescript中,我可以写:

    import * as ThisModule from 'this-module'
    import * as AnotherModule from 'another-module'
    import * as ThatModule from 'that-module'
    
    class MyClass{
        data():MyModuleTypeArray{
            return [
                ThisModule,
                AnotherModule,
                ThatModule
            ];
        }
    }
    

    我的问题 :我可以用Typescript为inline include编写代码,还是用其他方式编写代码,不需要写3倍的名称(或使用辅助变量)?

    我当然会写 require 但是 返回 any . 我要检查一下类型。

    0 回复  |  直到 6 年前