I'm kinda new to typescript so this one is confusing for me. I wanted to pass generic type into my hoc. I need to pass component props as a generic type to get Component with that types on it.
const withHOC = <T extends {}>(Component: ComponentType<T>) => (props: T) => { return (<Component {...props} /> )}//example: const MyView = withHoc<ViewProps>(View)
What I don't understand is that I can't just set <T>
as generic type, I must set it as <T extends something>
. With that said if I don't pass generic type (as shown in example) I wont get typescript warning for not passing generic type.Can someone explain me why is that happening?
I want it to look like this:
const withHOC = <T>(Component: ComponentType<T>) => (props: T) => { return (<Component {...props} /> )}
So when I don't pass generic type when calling withHOC, it warns me there has to be one. I might me doing everything wrong and asking for something that is not achievable so correct me if I'm wrong.