Skip to content

Type parameter on higher-order-component doesn't seem to work #28720

@MLoughry

Description

@MLoughry

TypeScript Version: 3.2.0-rc, 9319ea4

Search Terms:
higher order component, React, type parameter

Code

import * as React from 'react';

export interface ComponentProps {
    foo: number;
}

export default <P extends ComponentProps>(WrappedComponent: React.ComponentType<P>) => {
    return class SomeHOC extends React.Component<P, {}> {
        render() {
            return <WrappedComponent foo={0} />;
        }
    };
}

Expected behavior:
No error (as in 3.1.6)

Actual behavior:

src/wrappedComponent.tsx:10:21 - error TS2322: Type '{ foo: number; }' is not assignable to type 'IntrinsicAttributes & P & { children?: ReactNode; }'.
  Property 'foo' does not exist on type 'IntrinsicAttributes & P & { children?: ReactNode; }'.

10             return <WrappedComponent foo={0} />;

Playground Link:

Related Issues:
Possibly #28636, #28647, #28719

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    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