首页/文档/工具类型

工具类型

TypeScript内置的工具类型

高级

概述

TypeScript提供了许多内置的工具类型,用于操作和转换类型。

这些工具类型可以帮助你:

  • 创建新类型
  • 修改现有类型
  • 组合多个类型

Partial和Required

typescript
加载中...

Pick和Omit

typescript
加载中...

Record和Readonly

typescript
加载中...

其他工具类型

其他工具类型

TypeScript还提供了其他有用的工具类型:

  • Exclude:从联合类型中排除某些类型
  • Extract:从联合类型中提取某些类型
  • NonNullable:排除null和undefined
  • ReturnType:获取函数返回类型
  • InstanceType:获取类实例类型
type T0 = Exclude<"a" | "b" | "c", "a">; // "b" | "c"
type T1 = Extract<"a" | "b" | "c", "a" | "f">; // "a"
type T2 = NonNullable<string | null | undefined>; // string