Skip to content

Instantly share code, notes, and snippets.

@roalcantara
Last active September 6, 2020 09:06
Show Gist options
  • Save roalcantara/de21a757f3a9e597eae6b24db25fd4bc to your computer and use it in GitHub Desktop.
Save roalcantara/de21a757f3a9e597eae6b24db25fd4bc to your computer and use it in GitHub Desktop.
TypeScript 3.9 | Advanced Types: Takes a tuple T and drops the first N entries
type Tail<T extends any[]> = ((...t: T) => any) extends (
_: any,
...tail: infer TT
) => any
? TT
: []
type Prepend<E, T extends any[]> = ((head: E, ...args: T) => any) extends (
...args: infer U
) => any
? U
: T
type Drop<N extends number, T extends any[], I extends any[] = []> = {
0: Drop<N, Tail<T>, Prepend<any, I>>
1: T
}[Length<T> extends N ? 1 : 0]
type FirstEntries = Drop<2, [0, 1, 2, 3]> // [2, 3]
// 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