Title: Higher order inference for lookup types does not work · Issue #20124 · microsoft/TypeScript · GitHub
Open Graph Title: Higher order inference for lookup types does not work · Issue #20124 · microsoft/TypeScript
X Title: Higher order inference for lookup types does not work · Issue #20124 · microsoft/TypeScript
Description: Inference for T[K] to U[Y] was supposedly introduced in #18391, however looking over the code, this case in inferTypes in checker.ts: else if (source.flags & TypeFlags.IndexedAccess && target.flags & TypeFlags.IndexedAccess) { inferFromT...
Open Graph Description: Inference for T[K] to U[Y] was supposedly introduced in #18391, however looking over the code, this case in inferTypes in checker.ts: else if (source.flags & TypeFlags.IndexedAccess && target.flags...
X Description: Inference for T[K] to U[Y] was supposedly introduced in #18391, however looking over the code, this case in inferTypes in checker.ts: else if (source.flags & TypeFlags.IndexedAccess && ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/20124
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Higher order inference for lookup types does not work","articleBody":"Inference for `T[K]` to `U[Y]` was supposedly introduced in #18391, however looking over the code, this case in `inferTypes` in `checker.ts`:\r\n```ts\r\n else if (source.flags & TypeFlags.IndexedAccess && target.flags & TypeFlags.IndexedAccess) {\r\n inferFromTypes((\u003cIndexedAccessType>source).objectType, (\u003cIndexedAccessType>target).objectType);\r\n inferFromTypes((\u003cIndexedAccessType>source).indexType, (\u003cIndexedAccessType>target).indexType);\r\n }\r\n```\r\nis unreachable code.\r\nThis is because the first `if` statement in the `if-else if` chain is\r\n```ts\r\nif (target.flags & TypeFlags.TypeVariable) {\r\n```\r\nwhich is _true_ when the `target` is `TypeFlags.IndexedAccess`, as `TypeFlags.TypeVariable = TypeFlags.TypeParameter | TypeFlags.IndexedAccess`.\r\n\r\n\r\n**TypeScript Version:** 2.6.1-insiders.20171019 (current playground)\r\n\r\n**Code**\r\n\r\n```ts\r\ndeclare function get\u003cU, Y extends keyof U>(x: U, y: Y): U[Y];\r\ndeclare function find\u003cT, K extends keyof T>(o: T[K]): [T, K];\r\n\r\nfunction impl\u003cA, B extends keyof A>(a: A, b: B) {\r\n const item = get(a, b);\r\n return find(item);\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n`impl` has return type `[A, B]`\r\n\r\n**Actual behavior:**\r\n`impl` has return type `[{}, never]`\r\n","author":{"url":"https://github.com/weswigham","@type":"Person","name":"weswigham"},"datePublished":"2017-11-18T04:34:26Z","url":"https://github.com/microsoft/TypeScript/issues/20124"}
| 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:ea94475e-afd7-2e7e-2c64-6584a2ecf819 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A684:4D9F2:E56809:131273D:6B01D51E |
| html-safe-nonce | 78c66cad906ba2d74054e85cc6f9078b6ae7424c4f24d72f1bde8882e698ac8d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjg0OjREOUYyOkU1NjgwOToxMzEyNzNEOjZCMDFENTFFIiwidmlzaXRvcl9pZCI6IjI3OTY4NTk2NjI0NTA5MzkxNjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1862431889f1acbb28bc50263614d885638b20e6c5e8f7a15a67670e3c599d3d |
| hovercard-subject-tag | issue:275052645 |
| 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/20124/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0271cef5364d61d62d1b4b775392c6ffbc277e35fb73751f12c6182ff4281d65/microsoft/TypeScript/issues/20124 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0271cef5364d61d62d1b4b775392c6ffbc277e35fb73751f12c6182ff4281d65/microsoft/TypeScript/issues/20124 |
| og:image:alt | Inference for T[K] to U[Y] was supposedly introduced in #18391, however looking over the code, this case in inferTypes in checker.ts: else if (source.flags & TypeFlags.IndexedAccess && target.flags... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | weswigham |
| 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