Partial<T>Partial<T>: 意味 T 集合的子集;
Pick<T, K>Pick<T, K>: 相对 Partial<T>, Pick<T, K> 限制了子集中必须含有 K 定义的类型字段。
interface Todo {title: string;description: string;completed: boolean;}type TodoPreview = Pick<Todo, "title" | "completed">;const todo: TodoPreview = {title: "Clean room",completed: false};
Readonly<T>Readonly<T>: T 中类型只读;
Record<K, T>Record<K, T>: 建立 K 到 T 之间的 map 映射。
interface PageInfo {title: string;}type Page = "home" | "about" | "contact";const x: Record<Page, PageInfo> = {about: { title: "about" },contact: { title: "contact" },home: { title: "home" }};
Omit<T, K>Omit<T, K>: 申明一个类型其在 T 类型中移除 K 中包含的属性值;
interface Todo {title: string;description: string;completed: boolean;}type TodoPreview = Omit<Todo, "description">;const todo: TodoPreview = {title: "Clean room",completed: false};
Exclude<T, U>Exclude<T, U>: 申明一个类型其在 T 类型中移除 U 中所包含的类型;type T0 = Exclude<"a" | "b" | "c", "a">; // "b" | "c"type T1 = Exclude<"a" | "b" | "c", "a" | "b">; // "c"type T2 = Exclude<string | number | (() => void), Function>; // string | number
Extract<T, U>Extract<T, U> — Extract from T those types that are assignable to U.NonNullable<T>NonNullable<T>: 申明一个类型其将 T 类型中的 null 与 undefined 移除;ReturnType<T>ReturnType<T> — Obtain the return type of a function type.InstanceType<T>InstanceType<T>: 申明一个由构造函数实例类型组合而成的类型;class C {x = 0;y = 0;}type T0 = InstanceType<typeof C>; // Ctype T1 = InstanceType<any>; // anytype T2 = InstanceType<never>; // anytype T3 = InstanceType<string>; // Errortype T4 = InstanceType<Function>; // Error