Title: Mapped conditional type leaks unbound type parameter · Issue #31326 · microsoft/TypeScript · GitHub
Open Graph Title: Mapped conditional type leaks unbound type parameter · Issue #31326 · microsoft/TypeScript
X Title: Mapped conditional type leaks unbound type parameter · Issue #31326 · microsoft/TypeScript
Description: TypeScript Version: 3.5.0-dev.20190509 Search Terms: generic type parameter, scope leak, scope escape, conditional type, mapped type Code type Hmm
Open Graph Description: TypeScript Version: 3.5.0-dev.20190509 Search Terms: generic type parameter, scope leak, scope escape, conditional type, mapped type Code type Hmm
X 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 keyo...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/31326
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mapped conditional type leaks unbound type parameter","articleBody":"**TypeScript Version:** 3.5.0-dev.20190509\r\n\r\n**Search Terms:** generic type parameter, scope leak, scope escape, conditional type, mapped type\r\n\r\n**Code**\r\n\r\n```ts\r\ntype Hmm\u003cT, U extends T\u003e = U extends T ? { [K in keyof U]: number } : never;\r\ntype What = Hmm\u003c{}, { a: string }\u003e\r\n// type What = { [K in keyof (T \u0026 { a: string; })]: number; } 🤪\r\nconst w: What = { a: 4 }; // error! '{ a: number; }' not assignable to What\r\n```\r\n**Expected behavior:**\r\n`What` should be the concrete object type `{ a: number }` and therefore the assignment to `w` should compile without errors.\r\n\r\n**Actual behavior:**\r\nAn 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.\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior --\u003e [👨💻🔗](https://www.typescriptlang.org/play//#src=type%20Hmm%3CT%2C%20U%20extends%20T%3E%20%3D%20U%20extends%20T%20%3F%20%7B%20%5BK%20in%20keyof%20U%5D%3A%20number%20%7D%20%3A%20never%3B%0D%0Atype%20What%20%3D%20Hmm%3C%7B%7D%2C%20%7B%20a%3A%20string%20%7D%3E%0D%0A%2F%2F%20type%20What%20%3D%20%7B%20%5BK%20in%20keyof%20(T%20%26%20%7B%20a%3A%20string%3B%20%7D)%5D%3A%20number%3B%20%7D%20%F0%9F%A4%AA%0D%0Aconst%20w%3A%20What%20%3D%20%7B%20a%3A%204%20%7D%3B%20%20%2F%2F%20error!%20'%7B%20a%3A%20number%3B%20%7D'%20not%20assignable%20to%20What%0D%0A)\r\n\r\n**Related Issues:** \r\nProbably caused by: #29437\r\nPrior escapes: #31099 \r\nAlso: [Relevant SO question](https://stackoverflow.com/questions/56050214/typescript-nested-map-type-gives-confusing-type-hints)","author":{"url":"https://github.com/jcalz","@type":"Person","name":"jcalz"},"datePublished":"2019-05-09T15:07:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/31326/TypeScript/issues/31326"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:28199b14-972e-0a1d-0343-e774ac5c7dfb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9542:1256A0:3E338C:58CA8D:6A61CA23 |
| html-safe-nonce | f8b9e72fbd3c4e58f0278e25a53e3e25ab25c893cd091fcb2c16bf6607c9814d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NTQyOjEyNTZBMDozRTMzOEM6NThDQThEOjZBNjFDQTIzIiwidmlzaXRvcl9pZCI6IjgzNDY1NjUwMDA3MTU5NDY1MzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | be607e210b436a17e54731ba53346dde1e1948a75f2bef5721a8a7282d52fee2 |
| hovercard-subject-tag | issue:442287064 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/31326/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a06202abf3ea00c232f8df7c198d7b2faf37ef73e9622890d9db7b34556f6db8/microsoft/TypeScript/issues/31326 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a06202abf3ea00c232f8df7c198d7b2faf37ef73e9622890d9db7b34556f6db8/microsoft/TypeScript/issues/31326 |
| og:image:alt | TypeScript Version: 3.5.0-dev.20190509 Search Terms: generic type parameter, scope leak, scope escape, conditional type, mapped type Code type Hmm |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jcalz |
| hostname | github.com |
| expected-hostname | github.com |
| None | b2de8c74e5e61e893155ba46ee41bc66170c1644cb795adefa8386d490f7781c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d1866027ded575df8a15c731dd8b9986c9483ceb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width