Skip to content

Commit

Permalink
fix types on resultFunc (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdwain committed Dec 7, 2022
1 parent 32b6638 commit 9d5ec54
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
15 changes: 9 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ export interface CreateSelectorFunction<
): OutputSelector<
Selectors,
Result,
(...args: SelectorResultArray<Selectors>) => Result & Keys,
GetParamsFromSelectors<Selectors>
(...args: SelectorResultArray<Selectors>) => Result,
GetParamsFromSelectors<Selectors>,
Keys
> &
Keys

Expand All @@ -191,8 +192,9 @@ export interface CreateSelectorFunction<
): OutputSelector<
Selectors,
Result,
((...args: SelectorResultArray<Selectors>) => Result) & Keys,
GetParamsFromSelectors<Selectors>
((...args: SelectorResultArray<Selectors>) => Result),
GetParamsFromSelectors<Selectors>,
Keys
> &
Keys

Expand All @@ -204,8 +206,9 @@ export interface CreateSelectorFunction<
): OutputSelector<
Selectors,
Result,
(...args: SelectorResultArray<Selectors>) => Result & Keys,
GetParamsFromSelectors<Selectors>
(...args: SelectorResultArray<Selectors>) => Result,
GetParamsFromSelectors<Selectors>,
Keys
> &
Keys
}
Expand Down
14 changes: 8 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export type Selector<
: (state: State, ...params: Params) => Result

/** Selectors generated by Reselect have several additional fields attached: */
export interface OutputSelectorFields<Combiner extends UnknownFunction> {
export interface OutputSelectorFields<Combiner extends UnknownFunction, Keys> {
/** The final function passed to `createSelector` */
resultFunc: Combiner
/** The same function, memoized */
memoizedResultFunc: Combiner
memoizedResultFunc: Combiner & Keys
/** Returns the last result calculated by the selector */
lastResult: () => ReturnType<Combiner>
/** An array of the input selectors */
Expand All @@ -50,9 +50,10 @@ export type OutputSelector<
S extends SelectorArray,
Result,
Combiner extends UnknownFunction,
Params extends readonly any[] = never // MergeParameters<S>
Params extends readonly any[] = never, // MergeParameters<S>
Keys = {}
> = Selector<GetStateFromSelectors<S>, Result, Params> &
OutputSelectorFields<Combiner>
OutputSelectorFields<Combiner, Keys>

/** A selector that is assumed to have one additional argument, such as
* the props from a React component
Expand All @@ -68,8 +69,9 @@ export type OutputParametricSelector<
State,
Props,
Result,
Combiner extends UnknownFunction
> = ParametricSelector<State, Props, Result> & OutputSelectorFields<Combiner>
Combiner extends UnknownFunction,
Keys = {}
> = ParametricSelector<State, Props, Result> & OutputSelectorFields<Combiner, Keys>

/** An array of input selectors */
export type SelectorArray = ReadonlyArray<Selector>
Expand Down
9 changes: 9 additions & 0 deletions test/test_selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,15 @@ describe('defaultMemoize', () => {
// 'a' here would _not_ recalculate
selector('b') // ['b']
expect(funcCalls).toBe(5)

try{
//@ts-expect-error issue 591
selector.resultFunc.clearCache()
fail('should have thrown for issue 591')
}
catch(err) {
//expected catch
}
})
})

Expand Down

0 comments on commit 9d5ec54

Please sign in to comment.