# 定义
拓展运算符
# 使用
type spreadFirst<T> = T extends [infer First, ...infer Rest] ? First : never;
type spreadLast<T> = T extends [...infer First, infer Last] ? Last : never;
type spreadFirstChar<T> = T extends `${infer First}${infer Rest}`? First : never;
type spreadRestChar<T> = T extends `${infer First}${infer Rest}`? Rest : never;
1
2
3
4
5
6
7
2
3
4
5
6
7
# 快来耍耍啊
# 🌰🌰
type Arr = [1, 2, 3]
type Str = '123'
type Num = 123
type FA = spreadFirst<Arr> // 1
type LA = spreadLast<Arr> // 3
type FS = spreadFirstChar<Str> // 1
type LS = spreadRestChar<Str> // 23
type FN = spreadFirstChar<Num> // never
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 游乐场
# 参考答案
// answer
1