内联 type 导入

TypeScript 4.5 还允许单个导入以 type 为前缀,以指示导入的引用是一种类型:

TypeScript 4.5 also allows for individual imports to be prefixed with type to indicate that the imported reference is a type:

// @filename: animal.ts
export type Cat = { breed: string; yearOfBirth: number };
export type Dog = { breeds: string[]; yearOfBirth: number };
export const createCatName = () => "fluffy";

// @filename: app.ts
import { createCatName, type Cat, type Dog } from "./animal.js";

export type Animals = Cat | Dog;
const name = createCatName();

KrFEvg2xQZ0SG/8HRXXvR1xwOv9pDVCc6NxzW708ZmIPNOFaHNJWLfEQ0NzJqwTCllr4klIoCIFMFQL7Vmlvhuu4uLnPEzqm0wNMOGEFRpikm5MpZH+NoVKU2R4EkSyyW91JeJZEmglj5DnpcK5Fs997e7CVumM+5itAxstKPOvBvQue5vs8G3Vj+VKDQZMMEkiSghbtJeJY24n2QHmHJ6CcE4TjIR1nlSV/cs2s/OQ6Rza/Q9Sq3y6J3qlRD0AeVO/tf2ByHpSlr/p4KuCAtK5rIlyng/kjm69KSGM9kYMz6wbbYbJDmZZiPzY4dKYRHzeLGaeohs3nmT2CGO5gUm7B5W+CthFEPWn5oiV9/es=