Skip to content

Commit

Permalink
Fix type issues with lower TS versions
Browse files Browse the repository at this point in the history
  • Loading branch information
aryaemami59 committed Oct 24, 2023
1 parent 96d323e commit 5604b31
Showing 1 changed file with 42 additions and 35 deletions.
77 changes: 42 additions & 35 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ export type Selector<
// The result will be inferred
Result = unknown,
// There are either 0 params, or N params
Params extends readonly any[] = any[]
Params extends never | readonly any[] = any[]
// If there are 0 params, type the function as just State in, Result out.
// Otherwise, type it as State + Params in, Result out.
> =
/**
* A function that takes a state and returns data that is based on that state.
*
* @param state - The first argument, often a Redux root state object.
* @param params - All additional arguments passed into the selector.
* @returns A derived value from the state.
*/
(state: State, ...params: FallbackIfNever<Params, []>) => Result
> = [Params] extends [never]
? (state: State) => Result
: (state: State, ...params: Params) => Result
// /**
// * A function that takes a state and returns data that is based on that state.
// *
// * @param state - The first argument, often a Redux root state object.
// * @param params - All additional arguments passed into the selector.
// * @returns A derived value from the state.
// */
// (state: State, ...params: FallbackIfNever<Params, []>) => Result

/**
* A function that takes input selectors' return values as arguments and returns a result. Otherwise known as `resultFunc`.
Expand Down Expand Up @@ -64,8 +66,8 @@ export type Combiner<InputSelectors extends SelectorArray, Result> =
* @template ArgsMemoizeFunction - The type of the optional memoize function that is used to memoize the arguments passed into the output selector generated by `createSelector` (e.g., `defaultMemoize` or `weakMapMemoize`). If none is explicitly provided, `defaultMemoize` will be used.
*/
export interface OutputSelectorFields<
InputSelectors extends SelectorArray = SelectorArray,
Result = unknown,
InputSelectors extends SelectorArray,
Result,
MemoizeFunction extends UnknownMemoizer = typeof defaultMemoize,
ArgsMemoizeFunction extends UnknownMemoizer = typeof defaultMemoize
> extends Required<
Expand Down Expand Up @@ -98,17 +100,22 @@ export interface OutputSelectorFields<
* @template ArgsMemoizeFunction - The type of the optional memoize function that is used to memoize the arguments passed into the output selector generated by `createSelector` (e.g., `defaultMemoize` or `weakMapMemoize`). If none is explicitly provided, `defaultMemoize` will be used.
*/
export type OutputSelector<
InputSelectors extends SelectorArray = SelectorArray,
Result = unknown,
InputSelectors extends SelectorArray,
Result,
MemoizeFunction extends UnknownMemoizer = typeof defaultMemoize,
ArgsMemoizeFunction extends UnknownMemoizer = typeof defaultMemoize
> = PrepareOutputSelector<
InputSelectors,
> = Selector<
GetStateFromSelectors<InputSelectors>,
Result,
MemoizeFunction,
ArgsMemoizeFunction
GetParamsFromSelectors<InputSelectors>
> &
ExtractMemoizerFields<ArgsMemoizeFunction>
ExtractMemoizerFields<ArgsMemoizeFunction> &
OutputSelectorFields<
InputSelectors,
Result,
MemoizeFunction,
ArgsMemoizeFunction
>

/**
* A helper type designed to optimize TypeScript performance by composing parts of {@linkcode OutputSelector | OutputSelector} in a more statically structured manner.
Expand All @@ -130,22 +137,22 @@ export type OutputSelector<
*
* @see {@link https://github.com/microsoft/TypeScript/wiki/Performance#preferring-interfaces-over-intersections | Reference}
*/
export interface PrepareOutputSelector<
InputSelectors extends SelectorArray = SelectorArray,
Result = unknown,
MemoizeFunction extends UnknownMemoizer = typeof defaultMemoize,
ArgsMemoizeFunction extends UnknownMemoizer = typeof defaultMemoize
> extends OutputSelectorFields<
InputSelectors,
Result,
MemoizeFunction,
ArgsMemoizeFunction
>,
Selector<
GetStateFromSelectors<InputSelectors>,
Result,
GetParamsFromSelectors<InputSelectors>
> {}
// export interface PrepareOutputSelector<
// InputSelectors extends SelectorArray = SelectorArray,
// Result = unknown,
// MemoizeFunction extends UnknownMemoizer = typeof defaultMemoize,
// ArgsMemoizeFunction extends UnknownMemoizer = typeof defaultMemoize
// > extends OutputSelectorFields<
// InputSelectors,
// Result,
// MemoizeFunction,
// ArgsMemoizeFunction
// >,
// Selector<
// GetStateFromSelectors<InputSelectors>,
// Result,
// GetParamsFromSelectors<InputSelectors>
// > {}

/**
* A selector that is assumed to have one additional argument, such as
Expand Down

0 comments on commit 5604b31

Please sign in to comment.