如何从特定文件导入所有类型?
假设我有 myClass.ts
和 otherClass.ts
。
我想从 otherClass.ts
导入所有类。
我见过很少的导入语法。
import ClassA, { ClassB, ClassC } from 'otherClass';
import * as foo from 'otherClass';
import foo = require('otherClass');
import 'rxjs/Rx';
第一个需要我列出所有内容。我想导入所有类型。
第二种语法需要命名空间前缀:
foo.ClassA
。我知道最后一个是 TypeScript 1.4,但仍然支持。
有没有类似下面的东西?
import * from "otherClass";
...
var x = new ClassA()
此外,{ ... }
的含义是什么,有些类型在外部,有些在内部?
documentation没有暗示这样的事情。
最佳答案
对于 ES6 模块,最接近您想要的是命名空间导入:
import * as foo from './otherClass';
使用它单独导出为
foo.ClassA
您可以在 import
documentation 中看到可用的导入类型.
Also, what's the meaning of the { ... } and some of the types being outside and some inside?
那是为了导入命名导出。您可以在我引用的文档或 my answer here 中阅读相关内容.
关于javascript - TypeScript/JavaScript - 导入所有类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36293160/