简体   繁体   English

从 Typescript 文件导出多个接口

[英]Export multiple interfaces from a Typescript file

There are multiple interfaces in my typescript file which I need to export.我需要导出的 typescript 文件中有多个接口。 Something like:就像是:

interface A {
 ...
}

interface B {
 ...
}

Then in another file I need to use然后在另一个文件中我需要使用

const var : A

I have searched and tried multiple things, but till not only export default works for me.我已经搜索并尝试了多种方法,但直到不仅导出默认值对我有用。 But export default only works for one interface.但是导出默认值仅适用于一个接口。 I can't export multiple.我不能导出多个。 Is there a workaround for this?有解决方法吗?

Should work:应该管用:

export interface A {
 ...
}

export interface B {
 ...
}
import type { A, B } from '...';

const var1: A = ...

I had the same problem:D... In one (generated) ts file i had multiple exported interfaces, and including multiple interfaces worked.我有同样的问题:D ...在一个(生成的)ts文件中,我有多个导出的接口,并且包括多个接口工作。 In another file it didn't.在另一个文件中没有。 I am having a vue3 project.我有一个 vue3 项目。 Recompiling the project / restarting the development server resolved the issue in the end.重新编译项目/重新启动开发服务器最终解决了这个问题。 (i swear i tried that multiple times and it did not work at first;) (我发誓我试过很多次,一开始没有用;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM