gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 03:19:17 26 4
gpt4 key购买 nike

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

假设我有 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com