-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix incorrect RTKQ endpoint definition types for correct selector typings #1818
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 17f033e:
|
size-limit report 📦
|
The `ReducerPath` type tries to extract the generic type for "the path of the reducer" arg from `EndpointDefinitions`. However, it looks like this was always off by one: getting the 4th arg instead of the actual 5th arg. This caused bad input to the generated selectors. That seems to have worked okay with Reselect 4.0 and its looser types, but caused problems when we updated to Reselect 4.1.x and its improved types. The `RootState` type collapsed down to an empty object, because there was no valid string to use as an object key. This fixes the bug and adds a typetest to verify that the selector types are carried through all the way.
markerikson
force-pushed
the
bugfix/1817-rtkq-selectors
branch
from
December 10, 2021 03:28
6736d08
to
17f033e
Compare
phryneas
reviewed
Dec 10, 2021
@@ -464,8 +464,9 @@ export type QueryArgFrom<D extends BaseEndpointDefinition<any, any, any>> = | |||
export type ResultTypeFrom<D extends BaseEndpointDefinition<any, any, any>> = | |||
D extends BaseEndpointDefinition<any, any, infer RT> ? RT : unknown | |||
|
|||
export type ReducerPathFrom<D extends EndpointDefinition<any, any, any, any>> = | |||
D extends EndpointDefinition<any, any, any, infer RP> ? RP : unknown | |||
export type ReducerPathFrom< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Daaamn, good find!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR:
ReducerPath
type that was extracting the wrong generic fromEndpointDefinitions
, causing a cascade that resulted in typed Reselect selectors getting astate: {}
parameteroptimisticUpdates.test.ts
and additionally works around some odd behavior with mockingbaseQuery()
that was resulting in extra console errorsFixes #1817 .
As best as I can tell, the incorrect
ReducerPath
type was there since at least 1.6.0. I think we always had a bug here, but the use of Reselect 4.0 with its looser types must have masked it. When we updated to Reselect 4.1.x with improved type inference, we uncovered this bug.