Last active
July 23, 2020 13:56
-
-
Save antfu/ea8325bebcafc7361185981b321003fe 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
type Unexact<T> = | |
T extends null | |
? null | |
: T extends undefined | |
? undefined | |
: T extends number | |
? number | |
: T extends boolean | |
? boolean | |
: T extends string | |
? string | |
: T extends Promise<infer R> | |
? Promise<Unexact<R>> | |
: T extends (...args: infer A) => infer R | |
? (...args: Unexact<A>) => Unexact<R> | |
: T extends object | |
? { -readonly [K in keyof T]: Unexact<T[K]> } | |
: never | |
// usage | |
type a = Unexact<'1234'> // string | |
type b = Unexact<() => true> // () => boolean | |
type c = Unexact<{ a: 1234, b: 'foo' }> // { a: number, b: string } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment