Skip to content

Instantly share code, notes, and snippets.

@roalcantara
Last active September 6, 2020 09:06
Show Gist options
  • Save roalcantara/dee8e49f1f78ed9dee4fc46fc6f7e29e to your computer and use it in GitHub Desktop.
Save roalcantara/dee8e49f1f78ed9dee4fc46fc6f7e29e to your computer and use it in GitHub Desktop.
TypeScript 3.9 | Advanced Types: Adds a type E at the top of a tuple T
type Prepend<E, T extends any[]> = ((head: E, ...args: T) => any) extends (
...args: infer U
) => any
? U
: T
type Prepend01 = Prepend<string, []> // [string]
type Prepend02 = Prepend<string, [1, 2]> // [string, 1, 2]
// 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