Skip to content

Commit

Permalink
fix(store): add explicit overloads for createSelector (#3354)
Browse files Browse the repository at this point in the history
Closes #3268
  • Loading branch information
david-shortman authored Mar 26, 2022
1 parent 44076f7 commit 2f82101
Showing 1 changed file with 73 additions and 3 deletions.
76 changes: 73 additions & 3 deletions modules/store/src/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,81 @@ export function defaultMemoize(
return { memoized, reset, setResult, clearResult };
}

export function createSelector<State, S1, Result>(
s1: Selector<State, S1>,
projector: (s1: S1) => Result
): MemoizedSelector<State, Result>;
export function createSelector<State, S1, S2, Result>(
s1: Selector<State, S1>,
s2: Selector<State, S2>,
projector: (s1: S1, s2: S2) => Result
): MemoizedSelector<State, Result>;
export function createSelector<State, S1, S2, S3, Result>(
s1: Selector<State, S1>,
s2: Selector<State, S2>,
s3: Selector<State, S3>,
projector: (s1: S1, s2: S2, s3: S3) => Result
): MemoizedSelector<State, Result>;
export function createSelector<State, S1, S2, S3, S4, Result>(
s1: Selector<State, S1>,
s2: Selector<State, S2>,
s3: Selector<State, S3>,
s4: Selector<State, S4>,
projector: (s1: S1, s2: S2, s3: S3, s4: S4) => Result
): MemoizedSelector<State, Result>;
export function createSelector<State, S1, S2, S3, S4, S5, Result>(
s1: Selector<State, S1>,
s2: Selector<State, S2>,
s3: Selector<State, S3>,
s4: Selector<State, S4>,
s5: Selector<State, S5>,
projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5) => Result
): MemoizedSelector<State, Result>;
export function createSelector<State, S1, S2, S3, S4, S5, S6, Result>(
s1: Selector<State, S1>,
s2: Selector<State, S2>,
s3: Selector<State, S3>,
s4: Selector<State, S4>,
s5: Selector<State, S5>,
s6: Selector<State, S6>,
projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5, s6: S6) => Result
): MemoizedSelector<State, Result>;
export function createSelector<State, S1, S2, S3, S4, S5, S6, S7, Result>(
s1: Selector<State, S1>,
s2: Selector<State, S2>,
s3: Selector<State, S3>,
s4: Selector<State, S4>,
s5: Selector<State, S5>,
s6: Selector<State, S6>,
s7: Selector<State, S7>,
projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5, s6: S6, s7: S7) => Result
): MemoizedSelector<State, Result>;
export function createSelector<State, S1, S2, S3, S4, S5, S6, S7, S8, Result>(
s1: Selector<State, S1>,
s2: Selector<State, S2>,
s3: Selector<State, S3>,
s4: Selector<State, S4>,
s5: Selector<State, S5>,
s6: Selector<State, S6>,
s7: Selector<State, S7>,
s8: Selector<State, S8>,
projector: (
s1: S1,
s2: S2,
s3: S3,
s4: S4,
s5: S5,
s6: S6,
s7: S7,
s8: S8
) => Result
): MemoizedSelector<State, Result>;

export function createSelector<State, Slices extends unknown[], Result>(
...args: [...Selector<State, unknown>[], unknown] &
...args: [...slices: Selector<State, unknown>[], projector: unknown] &
[
...{ [i in keyof Slices]: Selector<State, Slices[i]> },
(...s: Slices) => Result
...slices: { [i in keyof Slices]: Selector<State, Slices[i]> },
projector: (...s: Slices) => Result
]
): MemoizedSelector<State, Result>;

Expand Down

0 comments on commit 2f82101

Please sign in to comment.