Title: Unexpected intersection inferred from indexed type · Issue #35695 · microsoft/TypeScript · GitHub
Open Graph Title: Unexpected intersection inferred from indexed type · Issue #35695 · microsoft/TypeScript
X Title: Unexpected intersection inferred from indexed type · Issue #35695 · microsoft/TypeScript
Description: TypeScript Version: 3.7.2 Search Terms: type alias index signature intersection TS2345 Expected behavior: pass the type checks Actual behavior: fail with a TS2345 error data[key] // expected: (value: DataTypes[K]) => void // actual: Data...
Open Graph Description: TypeScript Version: 3.7.2 Search Terms: type alias index signature intersection TS2345 Expected behavior: pass the type checks Actual behavior: fail with a TS2345 error data[key] // expected: (valu...
X Description: TypeScript Version: 3.7.2 Search Terms: type alias index signature intersection TS2345 Expected behavior: pass the type checks Actual behavior: fail with a TS2345 error data[key] // expected: (valu...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/35695
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unexpected intersection inferred from indexed type","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**TypeScript Version:** 3.7.2\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** type alias index signature intersection TS2345\r\n\r\n**Expected behavior:** pass the type checks\r\n\r\n**Actual behavior:** fail with a TS2345 error\r\n\r\n```ts\r\ndata[key]\r\n// expected: (value: DataTypes[K]) => void\r\n// actual: Data[K], with value: never\r\n```\r\n\r\n\u003c!-- Did you find other bugs that looked similar? -->\r\n**Related Issues:** #31445, #35613\r\n\r\n**Note:** Although #35613 is marked as duplicated, I think a different approach than #31445 can be used to address this issue. Actually `data[key]` can be inferred as `(value: DataTypes[K]) => void`, which solves the problem.\r\n\r\n**Code**\r\n```ts\r\ninterface DataTypes {\r\n a: string\r\n b: number\r\n}\r\n\r\ntype Data = {\r\n [K in keyof DataTypes]: (value: DataTypes[K]) => void\r\n}\r\n\r\nfunction myFunc \u003cK extends keyof DataTypes> (data: Data, key: K, value: DataTypes[K]) {\r\n data[key](value)\r\n}\r\n\r\n```\r\n\r\n\r\n\r\n\u003cdetails>\u003csummary>\u003cb>Output\u003c/b>\u003c/summary>\r\n\r\n```ts\r\n\"use strict\";\r\nfunction myFunc(data, key, value) {\r\n data[key](value);\r\n}\r\n\r\n```\r\n\r\n\r\n\u003c/details>\r\n\r\n\r\n\u003cdetails>\u003csummary>\u003cb>Compiler Options\u003c/b>\u003c/summary>\r\n\r\n```json\r\n{\r\n \"compilerOptions\": {\r\n \"noImplicitAny\": true,\r\n \"strictNullChecks\": true,\r\n \"strictFunctionTypes\": true,\r\n \"strictPropertyInitialization\": true,\r\n \"strictBindCallApply\": true,\r\n \"noImplicitThis\": true,\r\n \"noImplicitReturns\": true,\r\n \"useDefineForClassFields\": false,\r\n \"alwaysStrict\": true,\r\n \"allowUnreachableCode\": false,\r\n \"allowUnusedLabels\": false,\r\n \"downlevelIteration\": false,\r\n \"noEmitHelpers\": false,\r\n \"noLib\": false,\r\n \"noStrictGenericChecks\": false,\r\n \"noUnusedLocals\": false,\r\n \"noUnusedParameters\": false,\r\n \"esModuleInterop\": true,\r\n \"preserveConstEnums\": false,\r\n \"removeComments\": false,\r\n \"skipLibCheck\": false,\r\n \"checkJs\": false,\r\n \"allowJs\": false,\r\n \"declaration\": true,\r\n \"experimentalDecorators\": false,\r\n \"emitDecoratorMetadata\": false,\r\n \"target\": \"ES2017\",\r\n \"module\": \"ESNext\"\r\n }\r\n}\r\n```\r\n\r\n\r\n\u003c/details>\r\n\r\n**Playground Link:** [Provided](http://www.typescriptlang.org/play/index.html?ssl=12&ssc=2&pln=1&pc=1#code/JYOwLgpgTgZghgYwgAgCJzHAKgTwA4QDOyA3gLABQyycAXMoWFKAOaXUBG9IArgLYdolAL6VKYfCnSZkAXlLtkAbQDSyUMgDWEHAHsYaDNkmEAuvQAUANzgAbHhHrTjBQqtMBKOQD5kV3cAAJiJiFDA8IAhgwLogyHw4AGIRCMgAPGoQAB6QIIHE2noGzriuvhaBRk5GADRaOvQqdTb2joaYpUTuXuRUyJWYSoWm1nYOHiEUQA)\r\n ","author":{"url":"https://github.com/shigma","@type":"Person","name":"shigma"},"datePublished":"2019-12-16T07:35:11Z","url":"https://github.com/microsoft/TypeScript/issues/35695"}
| 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:a2e29532-3108-ec8d-f19a-dbb6cc64d0d4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B2A4:6365:7BD3E8:A72CA7:6B00DF66 |
| html-safe-nonce | 7b0537979b26fe2db9dc18dd5287f48287a12bdf2fedc8852bef96df4cc0d997 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMkE0OjYzNjU6N0JEM0U4OkE3MkNBNzo2QjAwREY2NiIsInZpc2l0b3JfaWQiOiIzMDgxMzMyMDQ5NTkyNzcwNDA2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 29a9eea58d8e40a3cb7d2acc45926ec1ce444c08fcec2419bbb11cb1c46709a2 |
| hovercard-subject-tag | issue:538236887 |
| 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/35695/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7e79d86c0bd90e3ab60eabf0b61b0c82ea7d537b647ca3e4fd75a83c689295b2/microsoft/TypeScript/issues/35695 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7e79d86c0bd90e3ab60eabf0b61b0c82ea7d537b647ca3e4fd75a83c689295b2/microsoft/TypeScript/issues/35695 |
| og:image:alt | TypeScript Version: 3.7.2 Search Terms: type alias index signature intersection TS2345 Expected behavior: pass the type checks Actual behavior: fail with a TS2345 error data[key] // expected: (valu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | shigma |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| 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 | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width