Closed
Description
TypeScript Version: 3.5.0-dev.20190509
Search Terms: generic type parameter, scope leak, scope escape, conditional type, mapped type
Code
type Hmm<T, U extends T> = U extends T ? { [K in keyof U]: number } : never;
type What = Hmm<{}, { a: string }>
// type What = { [K in keyof (T & { a: string; })]: number; } 🤪
const w: What = { a: 4 }; // error! '{ a: number; }' not assignable to What
Expected behavior:
What
should be the concrete object type { a: number }
and therefore the assignment to w
should compile without errors.
Actual behavior:
An unbound type parameter T
has escaped from its scope and is terrorizing the surrounding countryside. Please stay indoors with windows and doors locked until further notice.
Playground Link: 👨💻🔗
Related Issues:
Probably caused by: #29437
Prior escapes: #31099
Also: Relevant SO question