0

I recently discovered this section in the TypeScript docs which state that interfaces can extend classes: https://www.typescriptlang.org/docs/handbook/interfaces.html#interfaces-extending-classes

Seeing as a React component is essentially a class (except for functional components which are functions, I think), are there good use cases for having an interface extend a class in a React application?

Ogen
  • 6,499
  • 7
  • 58
  • 124
  • What a general TS feature has to do with react? Why not vuejs or angular? – zerkms Oct 03 '19 at 00:18
  • Because React components are classes, and my question is specifically with respect to a React application - is that not allowed? – Ogen Oct 03 '19 at 00:20
  • "is that not allowed" --- it's impossible to answer it. You've found a language feature and now you're asking how an arbitrary product may use it. If you don't need it - you don't need it, if you need it - you need it. :shrug: – zerkms Oct 03 '19 at 00:35
  • It's not arbitrary. React applications are commonly written with Typescript. And React components are javascript classes which means it is possible for a typescript interface to extend a react component. And I'm asking if there are any good use cases for doing so. It's definitely not impossible to answer... – Ogen Oct 03 '19 at 01:43
  • "if there are any good use cases for doing so" --- yep, you're extending a class with an interface when you need it. You don't do it casually because it's fun. – zerkms Oct 03 '19 at 03:03
  • Yeah you're almost there, when would I need it? Can you think of any use cases for when I may need it? Come on I believe in you! – Ogen Oct 03 '19 at 22:06
  • If my question about asking for a good use of a language feature is so ridiculous to you, why is this question so popular: https://stackoverflow.com/questions/420791/what-is-a-good-use-case-for-static-import-of-methods. – Ogen Oct 03 '19 at 22:39

0 Answers0