I have a collection of objects with similar structure:
const a = { x : true }
const b = { x : 5 }
const c = { x : `text` }
Every objects has an x field, but its type may be different.
All these objects are passed into a function f as a template tuple:
function f<
T extends { x : unknown[] }
>(
...t : [...{ [i in keyof T] : T[i] }]
) {
// return t[random index].x
}
f(a, b, c)
The function f has to return one of these x fields, but I can't figure out how to properly specify the return type for it.
For instance, in this particular case the type should be true | 5 | "text".
I have tried to put T[keyof T]["x"] as a result but got an error Type "x" cannot be used to index type 'T[keyof T]'.
How this should be done properly?