Is there a way to use react's ComponentProps type with generic-typed components?
For example:
function MyComponent<T extends string, N extends number>({ text, number }: { text: T; number: N }) {
return (
<div>
{text} - {number}
</div>
);
}
export type MyComponentProps = ComponentProps<typeof MyComponent>;
I expect MyComponentProps to be something like...
type MyComponentPropsExpected<T extends string, N extends number> = {
text: T;
number: N;
}
With the generics preserved. However, the type just drops the generic and fills all generics with their extends type. In this case the actual MyComponentProps type is...
type MyComponentProps = {
text: string;
number: number;
}
See demo here