Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
How to correctly extend class component in react typescript

I am trying to convert the current jsx code to typescript. The problem is with class component and extend it.

Example:

export default class ViewComponent<P, S> extends React.Component<P & IViewComponentProps, S> {}

export default class UIComponent<P, S> extends ViewComponent<P & IUIComponentProps, S & IUIComponentState> {}

export default class BasePopover<P, S> extends UIComponent<IBasePopoverProps, IBasePopoverState> {}

I am getting typescript error in UIComponent, whet I initialize this.state - TS2322: Type '{ hovered: false; focused: false; visible: true; }' is not assignable to type 'Readonly.

I tried to change UIComponent to

export default class UIComponent<P, S> extends ViewComponent<IUIComponentProps,IUIComponentState> {}

and then I have error in BasePopover TS2339: Property 'data' does not exist on type 'Readonly & Readonly{ children?: ReactNode; }>'

This is example code on github: https://github.com/Husamoa/typescript-extends-component

How to correctly do this in react typescript?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!