You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The projector argument (last argument) of createSelector is a pure function that uses the resultant values of the other selectors passed to define the result of a the new selector. It is available as the MemoizedSelector's project member, and this should be ideal for unit-testing selectors.
However, in all current signatures of createSelector, the ProjectorFn type argument of the return type MemoizedSelector is unspecified, meaning it defaults to DefaultProjectorFn<Result>, or (...args: any[]) => Result. It's nice that the Result type is available, but without the argument types, the unit tests become a little harder to write (at least for those of us who like to use Typescript to help guide their unit tests).
Luckily, this issue can be easily solved by simply providing the full projector type in createSelector's return type, e.g.
The text was updated successfully, but these errors were encountered:
MaximSagan
changed the title
createSelector should return MemoizedSelector<State, Result, ProjectorFn> with fully-typed ProjectorFn to assist in unit testing selectorscreateSelector should return MemoizedSelector<State, Result, ProjectorFn> with fully-typed ProjectorFn to assist in unit-testing selectors
Oct 22, 2021
The
projector
argument (last argument) ofcreateSelector
is a pure function that uses the resultant values of the other selectors passed to define the result of a the new selector. It is available as theMemoizedSelector
's project member, and this should be ideal for unit-testing selectors.However, in all current signatures of
createSelector
, theProjectorFn
type argument of the return typeMemoizedSelector
is unspecified, meaning it defaults toDefaultProjectorFn<Result>
, or(...args: any[]) => Result
. It's nice that theResult
type is available, but without the argument types, the unit tests become a little harder to write (at least for those of us who like to use Typescript to help guide their unit tests).Luckily, this issue can be easily solved by simply providing the full projector type in
createSelector
's return type, e.g.Before:
After:
Please see this Typescript playground link for a worker example of the additional type safety that this change would provide.
If accepted, I would be willing to submit a PR for this feature
[x] Yes (Preferably after #3023 is merged)
[ ] No
The text was updated successfully, but these errors were encountered: