Lets say I want to write a simple generic join function.
const join = <X, Y, T extends keyof (X & Y)>(key: T, a1: Array<X>, a2: Array<Y>) =>
a1.map(e1 => [ e1, a2.find(e2 => e2[key] === e1[key]) ])
T
should be a string which specifies on which attribute the function should join.
Sadly I get an error: T cannot be used to index type Y
This is weird since X & Y
is the intersection type thus all keys generated by the extends keyof expression should apply on X and on Y.