You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Is only 'Foo' a type? Or every declaration in the import?// We just give an error because it's not clear.importtypeFoo,{Bar,Baz}from"some-module";// ~~~~~~~~~~~~~~~~~~~~~~// error! A type-only import can specify a default import or named bindings, but not both.
The text was updated successfully, but these errors were encountered:
Content
TypeScript 3.8 adds a new syntax for type-only imports and exports.
⭕️
type-only import
不局限于 type 别名,也可以是 interface 接口TypeScript 引入 type-only 导入导出的目的:
import type 只导入用于类型注释和声明的声明。它在编译完成后总是被完全擦除,因此在运行时不会有任何残留。
同样,导出类型仅提供可用于类型上下文的导出,并且也会从 TypeScript 的输出中删除。
❗️❗️❗️
type-only import 要么是 default 引入,要么是具名引入。
在这一点上与 ES6 module import 有所区分,ES6 可同时引入一个 default + 若干具名接口。
The text was updated successfully, but these errors were encountered: