Last active
February 17, 2021 06:59
-
-
Save Oaphi/daf1516e47fb75b2fb9b4b4a4ef1d7eb to your computer and use it in GitHub Desktop.
Peculiar types found in TS land
This file contains hidden or 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
//@see https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887 | |
type swithcNever<T, A, B> = [T] extends [never] ? A : B; | |
//@see https://stackoverflow.com/a/63568058/11407695 | |
type Flatten<T extends any[]> = T extends [infer U, ...infer R] | |
? U extends any[] | |
? [...Flatten<U>, ...Flatten<R>] | |
: [U, ...Flatten<R>] | |
: []; | |
//@see https://stackoverflow.com/a/50375286/11407695 | |
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment