It's easy to create a generic pair type ( simplest possible Tuple ) i.e.
type Pair<A, B> = [A, B]
The question is how to create an type which represents and array of such generic pairs.
The only requirement is for element in the array to be a pair. The type of the first element and the type of the second element ought to be polymorphic, any
does not make the cut, otherwise this would be satisfactory:
type Pair = [any, any]
type Pairs = Pair[]
Pair<T, K>
is the same as [T, K]
yes, it will do what you want but its syntactically unnecessary.
To create an array of tuples it just would be Array<[TYPE, TYPE]>
or [TYPE, TYPE][]
I feel like I am missing a nuance here.. But believe this is what you are asking for:
type Pair<T,K> = [T,K];
type Pairs<T,K> = Pair<T,K>[];
const apple: Pair<number,number> = [2,3];
const orange: Pair<number,number> = [3,4];
const food: Pairs<number, number> = [apple, orange];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With