【发布时间】:2021-08-09 06:35:48
【问题描述】:
TS 文档提到了接口和类型别名,但我似乎找不到太多关于将接口导入或导出为 type 的信息,并希望得到一些澄清:
例如一个接口可以导出为:
// located in ./MyInterface.ts
export interface MyInterface
{
foo: string;
bar: () => number;
}
export type {MyInterface as MyInterfaceType}
它可以导入为:import {MyInterface} from "./MyInterface"
或import type {MyInterface} from "./MyInterface"
或import {MyInterfaceType} from "./MyInterface"
或import type {MyInterfaceType} from "./MyInterface"
谁能解释每个接口导入之间的行为差异?
【问题讨论】:
标签: typescript types import interface export