在 Typescript 中重新导出类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36790911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reexport class in Typescript
提问by mleko
I have two classes in two files.
我在两个文件中有两个类。
//a.ts
export class A{}
//b.ts
export class B{}
How I can build file c.ts
from which I could import both classes?
我如何构建可以c.ts
从中导入两个类的文件?
import {A, B} from "c";
instead of
代替
import {A} from "a";
import {B} from "b";
I want to make kind of export facade. How to reexport type?
我想做一种出口外观。如何转口类型?
回答by mleko
I found answer by myself
我自己找到了答案
https://www.typescriptlang.org/docs/handbook/modules.html@Re-exports
https://www.typescriptlang.org/docs/handbook/modules.html@Re-exports
Code to do what I wanted
代码做我想做的事
//c.ts
export {A} from "a";
export {B} from "b";
Default export
默认导出
Assuming you have file
假设你有文件
//d.ts
export default class D{}
Re-export have to look like this
重新导出必须看起来像这样
//reexport.ts
export { default } from "d";
or
或者
//reexport.ts
export { default as D } from "d";
What happens here is that you're saying "I want to re-export the default export
of module "D" but with the name of D
这里发生的事情是你说“我想重新导出default export
模块“D”但名称为D