Skip to content

react-router: withRouter narrows components with any prop type to {} #24070

Description

@OliverJAsh

Given a component that has a props type of any, when wrapping the component in the withRouter HOC, the returned component has a prop type of {}. I would expect the return component to have a prop type of any.

any should not be narrowed to {}.

Components with any type are common when gradually migrating a codebase to TypeScript, where many components may have their prop types undefined whilst the codebase is gradually migrated.

Example:

import React, { SFC } from 'react';
import { withRouter } from 'react-router-dom';

const MyComponent: SFC<any> = () => null;

const MyComponentWithRouter = withRouter(MyComponent);

<MyComponentWithRouter
  // Unexpected error: Property 'foo' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Pick<any, never>, ComponentState>> & Rea...'.
  foo={1}
/>

Related gcanti/typelevel-ts#19

This issue was introduced by the change in #21329 /cc @Grmiade (PR author)


If you know how to fix the issue, make a pull request instead.

If you do not mention the authors the issue will be ignored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions