Closed as not planned
Description
🔎 Search Terms
generic properties, named generics, generics nested, generics indexed, keyed type template, reverse mapped types, generic bags
Related (but much larger) :
#54254
#51612
#55521
#53017
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ entirely.
⏯ Playground Link
💻 Code
const check = <T extends string>(x: T, y: T): void => {}
const f = <T extends string, U extends string>(x: T, y: U): void => {
/**
* ✅ correctly errors:
* Argument of type 'U' is not assignable to parameter of type 'T'.
* 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'
*/
check(x, y)
}
const g = <T extends { foo: string }, U extends { foo: string }>(x: T, y: U): void => {
/**
* ❌ no error, despite being no more assignable than above. We'd like something like:
* Argument of type 'U['foo']' is not assignable to parameter of type 'T['foo']'.
* 'U['foo]' is assignable to the constraint of type 'T['foo]', but 'T['foo']' could be instantiated with a different subtype of constraint 'string'
*
* Currently, when type-checking sub-properties, it looks like T and U are simply inferred as what they extends
* ie. T = { foo: string } et U = { foo: string }
**/
check(x.foo, y.foo)
}
🙁 Actual behavior
The sub-property is no more assignable than it's parent. But we get no error.
🙂 Expected behavior
Some type error on the second check similar to the first one.
Something like:
The Argument of type 'U['foo']' is not assignable to parameter of type 'T['foo']'.
'U['foo]' is assignable to the constraint of type 'T['foo]', but 'T['foo']' could be instantiated with a different subtype of constraint 'string'
Additional information about the issue
No response