Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapped conditional type leaks unbound type parameter #31326

Closed
jcalz opened this issue May 9, 2019 · 1 comment · Fixed by #31337
Closed

Mapped conditional type leaks unbound type parameter #31326

jcalz opened this issue May 9, 2019 · 1 comment · Fixed by #31337
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@jcalz
Copy link
Contributor

jcalz commented May 9, 2019

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

@ahejlsberg
Copy link
Member

This looks to be an issue in getAnonymousTypeInstantiation where we're computing the outer type parameters. We appear to miss the fact that the mapped type depends on T.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants