Skip to content

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

Closed as not planned
@cebamps

Description

@cebamps

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions