类型体操
- T[number]
type TNumber<T extends any[]> = T[number]
// 结果:1 | 2 | 3
type Result = TNumber<[1, 2, 3]>
ts- [...infer R, infer L]
type Last<T extends any[]> = T extends [...infer R, infer L] ? L : never
ts类型中可以这么写,js 中 rest element 必须放到最后
type TNumber<T extends any[]> = T[number]
// 结果:1 | 2 | 3
type Result = TNumber<[1, 2, 3]>
tstype Last<T extends any[]> = T extends [...infer R, infer L] ? L : never
ts类型中可以这么写,js 中 rest element 必须放到最后