Last active
October 21, 2020 12:56
-
-
Save tianyk/bc32aa5396f05763164ecd54550bcc42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
1. T extends (...args: any) => any 为约束条件,约束 T 的类型为 `(...args: any) => any` | |
2. T extends (...args: any) => infer R ? R : any 取值,如果 `T extends (...args: any) => R` 那么返回值为 `R` 否则为 `any` | |
``` | |
type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any; | |
``` | |
如果 T 是Promise 返回值为 `U` 否则 为 `never` | |
``` | |
type PromiseType<T> = T extends Promise<infer U> ? U : never; | |
type Optional<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment