Skip to content

Commit

Permalink
feat(api): add Select2/3/4 conditional types
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 14, 2019
1 parent 9e3bfde commit a4bfb88
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,22 @@ export type Predicate<T> = Fn<T, boolean>;
*/
export type Predicate2<T> = Fn2<T, T, boolean>;

export type Select2<T, Q, A, B> = T extends Q ? A : B;

export type Select3<T, Q1, Q2, A, B, C> = T extends Q1
? A
: T extends Q2
? B
: C;

export type Select4<T, Q1, Q2, Q3, A, B, C, D> = T extends Q1
? A
: T extends Q2
? B
: T extends Q3
? C
: D;

/**
* Higher order `Predicate` builder. Possibly stateful.
*/
Expand Down

0 comments on commit a4bfb88

Please sign in to comment.