TypeScript 速记
TypeScript 高频概念、常见选择和工具类型的速记入口,用于复习和面试前快速回顾。
#tech / dev
#resource / typescript
#type / snippet
#status / growing
#topic / interview
[!info] related notes
TypeScript 速记
高频类型
- string
- number
- boolean
- null
- undefined
- symbol
- bigint
高频组合
- array 数组
- tuple 元组
- object
- union
| - intersection
& - generic
<T>
高频特殊类型
- any
- unknown
- never
- void
高频判断方式
typeofinstanceofin- 判空
- 自定义类型谓词
arg is Type
高频工具类型
Partial<T>Required<T>Pick<T, K>Omit<T, K>Record<K, V>ReturnType<T>Parameters<T>Awaited<T>
高频选择题
unknown vs any
any:放弃类型检查unknown:先缩小再使用
type vs interface
interface更适合描述对象形状和扩展关系type更适合组合、联合、映射和别名
import type vs 普通 import
- 只做类型引用时优先
import type - 需要运行时值时用普通
import
常见跳转
- 编译器:tsc
- 配置:tsconfig 使用详解
- 类型检查:TypeScript 类型检查
- 工具类型面试:TS 常用工具类型有哪些,怎么用
- 高级类型:TypeScript 高级类型(条件类型、函数重载、可辨识联合、infer)