Consider the following scenario:
type MyType = 'val1' | 'val2' | 'val3';
const variable = 'val1' as MyType;
const val2 = 'val2';
const val3 = 'val3';
declare function test<U extends MyType>(...args: U[]): void;
test(val2, val3); // U successfully resolves to "val3" | "val2"
declare function test2<T, U extends T>(value: T | undefined, ...values: U[]): void;
test2(variable, val2, val3); // U gets widened to "val1" | "val2" | "val3"
In both functions test
and test2
, U extends MyType
.
It was expected that test2
would also resolve U
to
"val3" | "val2"
, similar to how it did in test
, but this is not the case.
What could be the reason for this discrepancy?