ts - infer
ru shui 2021-06-26 Less than 1 minute
# 提取 promise 中的类型。
type GetPromiseGen<T> = T extends Promise<infer U> ? U : never
interface Person {
name: string
age: number
}
let promise: Promise<Person>
type result = GetPromiseGen<Promise<Person>>
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10