javascript - TypeScript/JavaScript - 导入所有类型

标签 javascript typescript import ecmascript-6

如何从特定文件导入所有类型?

假设我有 myClass.tsotherClass.ts。 我想从 otherClass.ts 导入所有类。

我见过很少的导入语法。

import ClassA, { ClassB, ClassC } from 'otherClass';

import * as foo from 'otherClass';

import foo = require('otherClass');

import 'rxjs/Rx';
  1. 第一个需要我列出所有内容。我想导入所有类型。

  2. 第二种语法需要命名空间前缀:foo.ClassA

  3. 我知道最后一个是 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/

相关文章:

TypeScript 泛型 - 类型推断

mysql - 导入我的数据库时出错 : ERROR 1146 (42S02) at line 217004: Table 'caol2.cao_curriculo' doesn't exist

javascript - Greasemonkey:XPath 未返回 .xhtml 页面的结果

typescript - “void”返回类型未在 TypeScript 中检查——防止 float promise ?

javascript - Firebase 频繁出现 "A network error (such as timeout, interrupted connection or unreachable host) has occurred."

javascript - Angular Typescript - 从数组返回满足约束的对象数量

javascript - 如果文件A不存在,如何导入文件B?

postgresql - Postgres 导入双引号值

javascript - 在鼠标悬停或悬停时绑定(bind)到动态生成的元素

javascript - ES6类字段箭头函数作用域问题