Skip to content

Instantly share code, notes, and snippets.

@roalcantara
Last active September 6, 2020 09:08
Show Gist options
  • Save roalcantara/012206f986b13c1848a8362e22940d50 to your computer and use it in GitHub Desktop.
Save roalcantara/012206f986b13c1848a8362e22940d50 to your computer and use it in GitHub Desktop.
TypeScript 3.9 | Advanced Types: Extracts types from an array
type ArrayInfer<T> =
T extends (infer U)[]
? U
: never
const array = [0, 'data', 1, 'foo']
type Type1 = ArrayInfer<typeof array> // string | number
// https://medium.com/free-code-camp/typescript-curry-ramda-types-f747e99744ab
// https://github.com/millsp/medium/blob/master/types-curry-ramda/src/index.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment