TypeScript / JavaScript - import all types

后端 未结 2 714
萌比男神i
萌比男神i 2021-02-04 23:09

How can I import all types from certain file?

Let\'s say I have myClass.ts and otherClass.ts. I want to import all classes from otherClas

相关标签:
2条回答
  • 2021-02-04 23:53

    You can use triple slashes import:

    /// <reference path="./actionsCollection.ts" />
    

    They must have to be the on the first line(s) of the file.

    1. When do I need a triple slash reference?
    2. https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html
    0 讨论(0)
  • 2021-02-04 23:54

    With ES6 modules, the closest thing available to what you want is a namespace import:

    import * as foo from './otherClass';
    

    The use it individual exports as

    foo.ClassA
    

    You can see the available kinds of imports in the import documentation.

    Also, what's the meaning of the { ... } and some of the types being outside and some inside?

    That's for importing named exports. You can read about that in the documentation I referenced or in my answer here.

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