Skip to content

type annotation for higher order react component #6559

@bhavinkamani

Description

@bhavinkamani

I am trying to figure out type annotation for higher order react components. Here's my code

class A extends React.Component<any, any> {
  render() {
    return <div>Hello World</div>
  }
}

const HigherOrderComponent = (component:any) => {
  return class extends component {
    render() {
      return super.render();
    }
  };
};

export default HigherOrderComponent(A);

typescript compiler throws following error
Error:(23, 24) TS2507: Type 'any' is not a constructor function type

I tried couple of annotation such as <any, any>, <T extends React.Component<any, any>>. None of them is passing through compilation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions