Apologies for the rubbish question name. Here are the details.
I have a HoC/Mixin function
export function MyMixin<TOriginalProps>(WrappedComponent: React.ComponentClass<TOriginalProps & IExtraProps>): React.ComponentClass<TOriginalProps> {
return class extends React.Component<TOriginalProps> {
public render() {
const value = "something irrelevent to the question"
const props = {...this.props, extraProp: value}
return <WrappedComponent {...props} />;
}
}
}
export interface IExtraProps {
extraProp: string;
}
Now this works great for Components that have their own props such as
class MyComponent extends React.Component<MyProps & IExtraProps, MyState>
MyMixin(MyComponent) // this returns React.ComponentClass<TMyProps,any>
however for Components that don't have any props (apart from the props to 'mix in') it gives me something a little weird
class MyComponentNoProps extends React.Component<IExtraProps, MyState>
MyMixin(MyComponentNoProps) // this return React.ComponentClass<{children?: React.Node; extraProp: string;}, any>
I've tried adapting the MixinFunction to take default values for the type parameter, but I just can't get it to take.
Any ideas how I get a single function (overloads would be fine too) to handle this?
I've tried an overload that has no TOriginalProps Type, but it doesn't resolve properly. If I define that first, then everyone uses it and my components that should have props don't. If I define it second, no one uses it.
I'm guessing this is related to the fact I'm using React as it something to be inferring this weird {children: React.Node; extraProps: string} type from somewhere (