【发布时间】:2016-04-22 10:10:11
【问题描述】:
我在两个文件中有两个类。
//a.ts
export class A{}
//b.ts
export class B{}
我如何构建文件c.ts 来导入两个类?
import {A, B} from "c";
而不是
import {A} from "a";
import {B} from "b";
我想做一种出口外观。 如何重新导出类型?
【问题讨论】:
标签: typescript
我在两个文件中有两个类。
//a.ts
export class A{}
//b.ts
export class B{}
我如何构建文件c.ts 来导入两个类?
import {A, B} from "c";
而不是
import {A} from "a";
import {B} from "b";
我想做一种出口外观。 如何重新导出类型?
【问题讨论】:
标签: typescript
我自己找到了答案
https://www.typescriptlang.org/docs/handbook/modules.html@Re-exports
代码做我想做的事
//c.ts
export {A} from "a";
export {B} from "b";
默认导出
假设你有文件
//d.ts
export default class D{}
再出口必须是这样的
//reexport.ts
export { default } from "d";
或
//reexport.ts
export { default as D } from "d";
这里发生的情况是您说“我想重新导出模块“D”的default export,但名称为D
【讨论】:
A 和B 是默认(且未命名)导出怎么办? export A from 'a'投诉declaration or statement required
对于不想处理默认值的任何人,您可以重新导出导入的 像这样的模块
import {A} from './A.js';
import {B} from './B.js';
const C = 'some variable'
export {A, B, C}
这样您可以导出您在此文件中导入或声明的所有变量。
取自here
【讨论】:
export { A } from './A'; export { B } from './B'; export const C = '...'