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

TypeScript: not possible to use a component's store and context props when wrapped with connect HOC #2147

Closed
1 task done
cebamps opened this issue Mar 29, 2024 · 2 comments

Comments

@cebamps
Copy link

cebamps commented Mar 29, 2024

What version of React, ReactDOM/React Native, Redux, and React Redux are you using?

  • React: 18.2.0
  • ReactDOM: 18.2.0
  • Redux: @reduxjs/toolkit 2.2.2
  • React Redux: 9.1.0

What is the current behavior?

Components connected to Redux using the connect HOC do not type-check when used with TypeScript if they have one of the following props not connected to Redux:

This is unfortunate for me, because I work on a webapp in the domain of app stores, where store is a prop name we often use (and context as well).

The following compilation error messages are demonstrated in this demo:

Type '"android"' is not assignable to type '"android" & Store<any, UnknownAction, unknown>'.
Type '"here"' is not assignable to type '"here" & Context<ReactReduxContextValue<any, UnknownAction> | null>'.

What is the expected behavior?

I should be able to provide the component the store or context props without a type error.

Perhaps with some way of opting out of the context and store props offered by the connect HOC at the type level, or a more complete handling of these props that does not interfere when connecting a component that expects them (extending the existing ConnectPropsMaybeWithoutContext approach).

(For reference, older versions of the TypeScript types (from DefinitelyTyped) did not expose the react-redux context and store props in connected components, though I understand this is not something you would want to go back to.)

Which browser and OS are affected by this issue?

n/a

Did this work in previous versions of React Redux?

  • Yes
@markerikson
Copy link
Contributor

store and context are props that the connect wrapper specifically looks for. Think of them as being similar to the key and ref props from React - you can't use those names, they're reserved.

Afraid we have no plans to make changes to connect's types or behavior going forward. It's there, it works, but it's effectively deprecated - I'd strongly recommend using the hooks API instead, which won't have this concern because it's all your own components.

@markerikson markerikson closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2024
@cebamps
Copy link
Author

cebamps commented Mar 29, 2024

Thanks for the quick response, I understand. It is a tad annoying as it makes the upgrade from react-redux 7 a highly breaking change in my specific case, but we will find a way.

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

No branches or pull requests

2 participants