Skip to content

Instantly share code, notes, and snippets.

@ScriptRaccoon
Created July 7, 2023 11:52

Revisions

  1. ScriptRaccoon revised this gist Jul 7, 2023. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion tuple-type.ts
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    type Tuple<Length extends number, T, Accumulator extends T[] = []> = Accumulator["length"] extends Length ? Accumulator : Tuple<Length,T,[...Accumulator,T]>;
    type Tuple<Length extends number, T, Accumulator extends T[] = []> =
    Accumulator["length"] extends Length ?
    Accumulator :
    Tuple<Length,T,[...Accumulator,T]>;

    const example: Tuple<3,string> = ["hi","mom","!"];
  2. ScriptRaccoon created this gist Jul 7, 2023.
    3 changes: 3 additions & 0 deletions tuple-type.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    type Tuple<Length extends number, T, Accumulator extends T[] = []> = Accumulator["length"] extends Length ? Accumulator : Tuple<Length,T,[...Accumulator,T]>;

    const example: Tuple<3,string> = ["hi","mom","!"];