Skip to content

Instantly share code, notes, and snippets.

@Oaphi
Last active February 17, 2021 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Oaphi/daf1516e47fb75b2fb9b4b4a4ef1d7eb to your computer and use it in GitHub Desktop.
Save Oaphi/daf1516e47fb75b2fb9b4b4a4ef1d7eb to your computer and use it in GitHub Desktop.
Peculiar types found in TS land
//@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