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

高频判断方式

  • typeof
  • instanceof
  • in
  • 判空
  • 自定义类型谓词 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

常见跳转

创建于 2025/1/1 更新于 2026/5/27