小编Sna*_*nap的帖子

TypeScript - 作为类型导入和导出接口有什么作用?

TS 文档提到了接口和类型别名,但我似乎找不到太多有关导入或导出接口的信息,type并希望得到一些说明:

例如,接口可以导出为:

// located in ./MyInterface.ts
export interface MyInterface
{
    foo: string;
    bar: () => number;
}

export type {MyInterface as MyInterfaceType}
Run Code Online (Sandbox Code Playgroud)

它可以导入为:
import {MyInterface} from "./MyInterface"

import type {MyInterface} from "./MyInterface"
或任何人都可以解释每个接口导入之间
import {MyInterfaceType} from "./MyInterface"

import type {MyInterfaceType} from "./MyInterface"

行为差​​异吗?

import types export interface typescript

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

export ×1

import ×1

interface ×1

types ×1

typescript ×1