ts - infer

ru shui 2021-06-26 Typescript
  • Typescript
  • Infer
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

Last update: August 27, 2021 23:37
Contributors: Laishuxin