I have the following React functional component that takes generic parameters:
type Props<T, S> = {
data: T[]
additionalData: S
}
function Component<T, S = void>({
....
You can use it as follow:
<Component<Bike, BikeShed> data={bikes} additionalData={bikeShed} />
Since the second generic parameter is optional, you have to use it as follows:
<Component<Car> data={cars} additionalData={undefined} />
Now here is the question. Is there a way to omit the additionalData={undefined} because it is clearly not being used here.
What I tried is this:
type Props<T, S = void> = {
data: T[]
additionalData?: S
}
But it effectively changes S to S | undefined, not an ideal situation!
Can I set up my Props in a way where I don't have to specify its relating properties when the optional generic parameter is void?