Skip to content

Possible regression with ConnectedProps and React.ComponentProps<typeof ...> in 8.x #1955

Closed
@cascornelissen

Description

@cascornelissen

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

  • React: 16.14.0
  • ReactDOM: 16.14.0
  • Redux: 4.2.0
  • React Redux: 8.0.2
  • TypeScript: 4.8.3

What is the current behavior?

The following simplified snippet throws a TS2312 error after upgrading to react-redux v8.

import React from 'react';
import { connect, ConnectedProps } from 'react-redux';

interface Props extends React.ComponentProps<'div'>, ConnectedProps<typeof connector> {}

const ExampleComponent: React.FunctionComponent<Props> = ({ data, ...props }) => {
    return <div {...props} />
}

const mapStateToProps = (state: { data: unknown[] }) => ({
    data: state.data
});

const connector = connect(mapStateToProps);
const ConnectedExampleComponent = connector(ExampleComponent);

// This next line is where the error happens
interface Props2 extends React.ComponentProps<typeof ConnectedExampleComponent> {}
TS2312: An interface can only extend an object type or intersection of object types with statically known members.

There seem to be no apparent changes to the definition of ConnectedProps between @types/react-redux and react-redux so I'm not sure what could be causing this.

The changelog does mention changes to the types for connect where it no longer has the DefaultRootState included. But even changing the definition of connector in the example above to include a generic with any, {} or the actual global state interface does not resolve the issue.

What is the expected behavior?

It's still possible to use React.ComponentProps<typeof ...> like when using [email protected] with @types/[email protected]

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