Given the following:
type MyGeneric<S extends string> = {
prop: S;
};
type MyType = {
generics: MyGeneric[];
// Generic type 'MyGeneric' requires 1 type argument(s). ts(2314)
};
I want MyType
to have a list of those generics, which could all be different. E.g. MyGeneric<'hello'>
and MyGeneric<'world'>
could be objects inside the generics
array of MyType
. This is not possible in this scenario because TS expects a type argument in MyGeneric[]
.
If it was a single generic as a prop, I could just pass the parameter to MyType
, like this:
type MyType<S extends string, Generic extends MyGeneric<S>> = {
generics: Generic;
};
But in this case, it is an array.
Is it possible to have an array of multiple different generics, and if yes, how?
PS: If I made an English mistake or if any of this isn’t clear, please ask me.