Often times in React we have an HOC where we know there are certain required props. However, we also want the consumer of the HOC to be able to pass in any additional props they wish. This is pretty easy to do. The signature of the HOC uses destructing and rest like so:
const MyHOC = ({requiredBoolean, requiredCallback, ...restProps})
In the return, we simply pass the required props and then spread the rest:
return (
<SomeOtherComponent
requiredBoolean={requiredBoolean}
requiredCallback={requiredCallback}
{...restProps}
/>
)
The question is how to do exactly this but make it type safe with TS. Let's say that I want to make sure the required props are present and they are the correct type ...but I still want the consumer to be able to pass anything else they want.