TypeScript / JavaScript - 导入所有类型 [英] TypeScript / JavaScript - import all types

查看:1140
本文介绍了TypeScript / JavaScript - 导入所有类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从某个文件导入所有类型?

How can I import all types from certain file?

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

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

我看过很少的语法导入。

I've seen few syntaxes for imports.

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

import * as foo from 'otherClass';

import foo = require('otherClass');

import 'rxjs/Rx';




  1. 首先需要我列出所有内容。我想导入所有类型。

  1. The first needs me to list everything. I'd like to import all types.

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

The second syntax needs the namespace prefix: foo.ClassA.

我知道最后一个是TypeScript 1.4,但仍然受支持。

I understand that the last one is TypeScript 1.4, but still supported.

是否有如下内容?

import * from "otherClass";
...
   var x = new ClassA()

此外,什么是 {...} 的含义以及一些类型在外面和一些内部?

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

文档没有提示任何此类内容。

The documentation doesn't hint anything such.

推荐答案

使用ES6模块,最接近你的东西你想要的是命名空间导入:

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

import * as foo from './otherClass';

您可以在 import 文档

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?

您可以在我引用的文档中或我的回答

You can read about that in the documentation I referenced or in my answer here.

这篇关于TypeScript / JavaScript - 导入所有类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆