Here is a simple function that takes in an Iterable of Iterables.
function unwrapFirst<T extends Iterable<U>, U>(iter: Iterable<T>): U {
return [...[...iter][0]][0];
}
unwrapFirst([[1,2,3],[4,5,6]]);
I expected TypeScript to infer the type of U correctly as number but it infers it as unknown. Can someone explain why? And how to get TypeScript to correctly infer U?