Title: Intersection breaks generic key field inference · Issue #26409 · microsoft/TypeScript · GitHub
Open Graph Title: Intersection breaks generic key field inference · Issue #26409 · microsoft/TypeScript
X Title: Intersection breaks generic key field inference · Issue #26409 · microsoft/TypeScript
Description: TypeScript Version: 3.1.0-dev.20180810 Code const f =
Open Graph Description: TypeScript Version: 3.1.0-dev.20180810 Code const f =
X Description: TypeScript Version: 3.1.0-dev.20180810 Code const f = <T extends { [K0 in K]: string; } & { cool: string; }, K extends keyof T>(t: T, k: K) => { const s: string = t[k]; }; Expected beh...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/26409
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Intersection breaks generic key field inference","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.1.0-dev.20180810\r\n\r\n**Code**\r\n\r\n```ts\r\nconst f = \u003cT extends { [K0 in K]: string; } & { cool: string; }, K extends keyof T>(t: T, k: K) =>\r\n{\r\n const s: string = t[k];\r\n};\r\n```\r\n\r\n**Expected behavior:** Successful compilation\r\n\r\n**Actual behavior:** I get the following error:\r\n```\r\nerror TS2322: Type 'T[K]' is not assignable to type 'string'.\r\n\r\n const s: string = t[k];\r\n ~\r\n```\r\n\r\n**Playground Link:** [Link](https://www.typescriptlang.org/play/#src=const%20f%20%3D%20\u003cT%20extends%20%7B%20%5BK0%20in%20K%5D%3A%20string%3B%20%7D%20%26%20%7B%20cool%3A%20string%3B%20%7D%2C%20K%20extends%20keyof%20T>(t%3A%20T%2C%20k%3A%20K)%20%3D>%0D%0A%7B%0D%0A%20%20const%20s%3A%20string%20%3D%20t%5Bk%5D%3B%0D%0A%7D%3B%0D%0A)\r\n\r\n**Additional Notes:** This compiles successfully ([link](https://www.typescriptlang.org/play/#src=const%20f%20%3D%20\u003cT%20extends%20%7B%20%5BK0%20in%20K%5D%3A%20string%3B%20%7D%20%26%20%7B%20cool%3A%20string%3B%20%7D%2C%20K%20extends%20keyof%20T>(t%3A%20T%2C%20k%3A%20K)%20%3D>%0D%0A%7B%0D%0A%20%20const%20s%3A%20string%20%3D%20t%5B'cool'%5D%3B%0D%0A%7D%3B%0D%0A)):\r\n```ts\r\nconst f = \u003cT extends { [K0 in K]: string; } & { cool: string; }, K extends keyof T>(t: T, k: K) =>\r\n{\r\n const s: string = t['cool'];\r\n};\r\n```\r\nas does this ([link](https://www.typescriptlang.org/play/#src=const%20f%20%3D%20\u003cT%20extends%20%7B%20%5BK0%20in%20K%5D%3A%20string%3B%20%7D%2C%20K%20extends%20keyof%20T>(t%3A%20T%2C%20k%3A%20K)%20%3D>%0D%0A%7B%0D%0A%20%20const%20s%3A%20string%20%3D%20t%5Bk%5D%3B%0D%0A%7D%3B%0D%0A)):\r\n```ts\r\nconst f = \u003cT extends { [K0 in K]: string; }, K extends keyof T>(t: T, k: K) =>\r\n{\r\n const s: string = t[k];\r\n};\r\n```","author":{"url":"https://github.com/jeremybparagon","@type":"Person","name":"jeremybparagon"},"datePublished":"2018-08-13T15:02:45Z","url":"https://github.com/microsoft/TypeScript/issues/26409"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:3244c65a-8886-92c1-1456-8872a6d46477 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BBBC:311640:2BF8EF9:37ED189:6B01B4ED |
| html-safe-nonce | 44ff8484d649e6424d515dd0b979c6ef82063927272ddae83d186011035e5979 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkJDOjMxMTY0MDoyQkY4RUY5OjM3RUQxODk6NkIwMUI0RUQiLCJ2aXNpdG9yX2lkIjoiMzU4MDk4NjAzNDg4NTg2NjczMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f0f4ece25274452447339e53421abed1f1e9a4272bfac4765486abd5372dac69 |
| hovercard-subject-tag | issue:350068656 |
| 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/26409/issue_layout |
| twitter:image | https://opengraph.githubassets.com/068ae4ba2bb6ec32fb4625a53e1144f843a8e4b85eb3cefc0f7450b86a7ae94e/microsoft/TypeScript/issues/26409 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/068ae4ba2bb6ec32fb4625a53e1144f843a8e4b85eb3cefc0f7450b86a7ae94e/microsoft/TypeScript/issues/26409 |
| og:image:alt | TypeScript Version: 3.1.0-dev.20180810 Code const f = |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jeremybparagon |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width