Skip to content
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 addMatcher typings #1895

Merged
merged 3 commits into from
Jan 21, 2022
Merged

Conversation

crcarrick
Copy link
Contributor

@crcarrick crcarrick commented Jan 5, 2022

References #1861

Previously, the action argument passed down to the reducer function of addMatcher(matcher, reducer) would be incorrectly typed as AnyAction when the type predicate being tested by the matcher function didn't include a type property.

This PR attempts to resolve the issue:

  • Widens the type argument of ActionMatcher from A extends AnyAction to A.
  • Maintains the previous behavior of defaulting the type of the action argument to AnyAction when there is no type predicate.
  • Intersects the A type argument with AnyAction to satisfy the second type argument to CaseReducer and offer better completion inside the reducer function.
  • Adds a type test to the mapBuilders.typetest.ts file that verifies that the action argument is now correctly typed.

"If you changed external-facing types, make sure to also build the project locally and include the updated API report file etc/redux-toolkit.api.md in your pull request."

I was unable to accomplish this. I ran the monorepo build script and the @reduxjs/toolkit build scripts but this file was never updated. All of the build:* scripts in the @reduxjs/toolkit workspace's package.json file include the --skipExtraction flag which seems like it would prevent the extraction tool from running. addMatcher() and ActionMatcher are referenced in the etc/redux-toolkit.api.md file, so I think the file should be updated with this PR. If somebody could point me in the right direction on how to get the tooling to do that, I would be grateful.

Thanks for taking the time to look at this and let me know what you all think!

@crcarrick crcarrick changed the title Fix addMatcher typings Fix addMatcher typings (Issue #1861) Jan 5, 2022
@crcarrick crcarrick changed the title Fix addMatcher typings (Issue #1861) Fix addMatcher typings Jan 5, 2022
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 5, 2022

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 e1a3231:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
rsk-github-issues-example Configuration
reduxjs/redux-toolkit Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration

@netlify
Copy link

netlify bot commented Jan 5, 2022

✔️ Deploy Preview for redux-starter-kit-docs ready!

🔨 Explore the source changes: e1a3231

🔍 Inspect the deploy log: https://app.netlify.com/sites/redux-starter-kit-docs/deploys/61eac4b909d3a80007e36694

😎 Browse the preview: https://deploy-preview-1895--redux-starter-kit-docs.netlify.app

@msutkowski
Copy link
Member

msutkowski commented Jan 18, 2022

References #1861

Previously, the action argument passed down to the reducer function of addMatcher(matcher, reducer) would be incorrectly typed as AnyAction when the type predicate being tested by the matcher function didn't include a type property.

This PR attempts to resolve the issue:

  • Widens the type argument of ActionMatcher from A extends AnyAction to A.
  • Maintains the previous behavior of defaulting the type of the action argument to AnyAction when there is no type predicate.
  • Intersects the A type argument with AnyAction to satisfy the second type argument to CaseReducer and offer better completion inside the reducer function.
  • Adds a type test to the mapBuilders.typetest.ts file that verifies that the action argument is now correctly typed.

"If you changed external-facing types, make sure to also build the project locally and include the updated API report file etc/redux-toolkit.api.md in your pull request."

I was unable to accomplish this. I ran the monorepo build script and the @reduxjs/toolkit build scripts but this file was never updated. All of the build:* scripts in the @reduxjs/toolkit workspace's package.json file include the --skipExtraction flag which seems like it would prevent the extraction tool from running. addMatcher() and ActionMatcher are referenced in the etc/redux-toolkit.api.md file, so I think the file should be updated with this PR. If somebody could point me in the right direction on how to get the tooling to do that, I would be grateful.

Thanks for taking the time to look at this and let me know what you all think!

@crcarrick Ah... this isn't obvious at all, but you should just be able to run node scripts/cli.js --local (inside of packages/toolkit) to achieve this. We can revisit the package scripts + docs for this separately.

@phryneas
Copy link
Member

Tbh., I'm not even sure if the extraction step still works or if the CI actually uses it.

I've used this PR to add some minor refactoring (introducing a new TypeGuard type for this) and I've added a few more type assertions in the tests. Generally, this looks good for me.

@phryneas phryneas merged commit 18c3815 into reduxjs:master Jan 21, 2022
@phryneas
Copy link
Member

phryneas commented Feb 3, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants