gpt4 book ai didi

node.js - 从 TypeScript 项目中的一个文件中导出所有接口(interface)/类型

转载 作者:搜寻专家 更新时间:2023-10-30 22:04:48 25 4
gpt4 key购买 nike

我的库的直接接口(interface)被捕获

index.d.ts

这是当前自动生成的

index.ts

在我项目的 package.json 文件中,typings/types 属性指向这个 index.d.ts 文件,据我所知,它应该是这样的。到目前为止一切都很好。

但是,还有一些我想从 index.d.ts 中导出的类型目前没有在 index.d.ts 中表达。

例如我有一些手动创建的类型

foo.d.ts
bar.d.ts

我希望这些在 index.d.ts 中表达。

我认为唯一可行的方法是将 foo.d.ts/bar.d.ts 类型导入 index.d.ts,然后从该文件中导出它们。

但是,我遇到了麻烦!

这是我尝试过的:

// index.ts

import {IBar} from '../bar.d.ts'
import {IFoo} from '../foo.d.ts'

// ... do some stuff with index.ts yadda yadda

export type IBar = IBar; // doesn't seem to work
export interface IFoo = IFoo; // doesn't seem to work

这可能吗?我该怎么做?

最佳答案

如果不需要使用,可以直接导出。

export * from '../foo/bar';

或者如果您只需要导出其中的一部分,您可以使用。

export { IFoo, IBar} from '../foo/bar';

或者如果你想在导出过程中重命名它们,你可以这样做:

export { IFoo as IOther, IBar as Dogs } from '../foo/bar';

您可以在 MDN 文档中阅读更多关于它们的信息 here .

关于node.js - 从 TypeScript 项目中的一个文件中导出所有接口(interface)/类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44583372/

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