-
-
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
listenerMiddleware
type error in matcher using custom actions.
#4641
Comments
Could you post what the type error you're getting is? #3862 is also likely related. |
Thank you for the swift response. Here is the ts-error:
This does provide
|
No, |
listenerMiddleware
type error in matcher and predicate using custom actions.listenerMiddleware
type error in matcher using custom actions.
OK. The explanation of the issue still holds for matchers. Any suggestions on how I could fix this in either a PR or a workaround in my codebase? |
have you checked out the issue i linked, and tried moving the |
Yes, just tried and that didn't help. It works as expected when using RTK defined actions such as below. But not when using custom built matcher functions. const myThunk = createAsyncThunk.....;
const myMatcher = isAnyOf(myThunk.fulfilled),
startListening({
matcher: myMatcher,
effect: (action, listenerApi) => {
expectTypeOf(action).toMatchTypeOf<typeof myThunk....>()
},
}) |
Could you put together a reproduction of this, either in Typescript Playground or a repo i can checkout? |
Sure, here is a commit adding a testcase in a fork of this repo. Hope this is clear enough, otherwise let me know and I'll try to adjust! |
ok, that helped a little - it still won't work inline because of the TS bug mentioned previously, but i found a change that fixes it when the predicate is defined outside. Switching from UnknownAction to Action works: index b5980e10..eb42c86b 100644
--- a/packages/toolkit/src/listenerMiddleware/types.ts
+++ b/packages/toolkit/src/listenerMiddleware/types.ts
@@ -466,7 +466,7 @@ export type AddListenerOverloads<
): Return
/** Accepts an RTK matcher function, such as `incrementByAmount.match` */
- <MatchFunctionType extends MatchFunction<UnknownAction>>(
+ <MatchFunctionType extends MatchFunction<Action>>( Presumably this is because any This is briefly covered in this article by Matt Pocock. |
Oh, so the preferred way of declaring actions in a legacy type of application would be to use |
I have a codebase using legacy redux patterns and trying to slowly but steadily transition to using modern redux. I have a set of old Actions that are created similiar to
ExtraAction
mentioned below. When using thelistenerMiddleware
to add a set of type guards as matchers using theisAnyOf
utility as demonstrated below, I see a type error on the matcher.Also, it seems as the type inferred from the predicate (probably the matcher to) doesn't carry along into effect callback.The text was updated successfully, but these errors were encountered: