Skip to content

Commit

Permalink
Added OptionalTuple
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Apr 20, 2024
1 parent 39c4c2d commit 2d012fc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,8 @@ type _Tuple<T, N extends number, R extends unknown[] = Empty> = R['length'] exte
* Creates a tuple of T with length N
*/
export type Tuple<T, N extends number> = _Tuple<T, N>;

/**
* Makes all members of the tuple T optional
*/
export type OptionalTuple<T extends unknown[]> = T extends [infer Head, ...infer Tail] ? [Head?, ...OptionalTuple<Tail>] : T;

0 comments on commit 2d012fc

Please sign in to comment.