Is there any TypeScript solution, that would help me have an "infinite" amount of generic types, without having to type all of them, of course?
Example bellow:
type Args<T extends React.ComponentType<any>> = { component: T, presetProps: React.ComponentProps<T>};
function buildComponents<T extends React.ComponentType<any>>(...args: Args<T>[] ) : any
function componentJ({name, age}: {name: string, age: number}){
return <h1>123</h1>
}
function componentI({ age}: { age: number}){
return <h1>123</h1>
}
buildComponents({component:componentJ, presetProps:{name: "Jon", age: 12}},
{component: componentI, presetProps:{age: 44}})
With this code, I got an error on {component: componentI, presetProps:{age: 44}}, because it misses the name, but I wanted this to get the type from the componentI and not from the the componentJ, which was the case.