Sna*_*nap 5 import types export interface 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"
行为差异吗?
TypeScript 3.8 添加了仅类型导入和导出的新语法
\nexport type { MyInterface as MyInterfaceType }\nRun Code Online (Sandbox Code Playgroud)\n仅导出MyInterface带有 alias 的类型MyInterfaceType。
\n\n\n
export type仅提供可用于类型上下文的导出,并且也会从 TypeScript\xe2\x80\x99s 输出中删除。
和
\nexport interface MyInterface\n{\n foo: string;\n bar: () => number;\n}\nRun Code Online (Sandbox Code Playgroud)\n这是一个名为 export 的 ECMAScript 2015 模块。
\n\n\n从 ECMAScript 2015 开始,JavaScript 有了模块的概念。TypeScript 也有这个概念。
\n
\n\n\n任何声明(例如变量、函数、类、类型别名或接口)都可以通过添加export关键字来导出。
\n
| 归档时间: |
|
| 查看次数: |
12831 次 |
| 最近记录: |