Title: Intra expression inference doesn't work within reverse mapped types · Issue #53018 · microsoft/TypeScript · GitHub
Open Graph Title: Intra expression inference doesn't work within reverse mapped types · Issue #53018 · microsoft/TypeScript
X Title: Intra expression inference doesn't work within reverse mapped types · Issue #53018 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms intra expression inference reverse mapped type 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link Playground link with relevant code (object variant) Playground li...
Open Graph Description: Bug Report 🔎 Search Terms intra expression inference reverse mapped type 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link Playground link with rele...
X Description: Bug Report 🔎 Search Terms intra expression inference reverse mapped type 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link Playground link with ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/53018
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Intra expression inference doesn't work within reverse mapped types","articleBody":"# Bug Report\r\n\r\n### 🔎 Search Terms\r\n\r\nintra expression inference reverse mapped type\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This is the behavior in every version I tried\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code (object variant)](https://www.typescriptlang.org/play?ts=5.1.0-dev.20230227#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVIB4AVAPgAoAoeeWAcwC54BvK6+AbQGl4t8BrEAE8cieEQC6jFmzYAHGDmDIwIRmVSMAzhhi9aASngBeEmK7iA3Kxlg8m5AFtV8MgA9GRc4ZPwAbjixgKxkAX2D4EIp9Rn9AqwB6ePgAdRwYPk0KRDJpGilreHlFZWcyb1MAIgALEAgIHAqAGgLbVHsnNVdy+FcAOgwcABkcAHcQGABhKE0QMubqEOaQ-QSk1PTM7NyofJkipRU1DXhtXVQDY1NUebZW9tKuy57+odHxqZm51kWKZdWT7B1eDAHAgTSoADkGHgIzSfEa8BAvhA+BGWAwVXgFQAkg4isjgPAAGJoTC4fDY1CIcYolQ8fAAeQARgArcAYTQ0VCEgCyIAxik0FRofCg9J0UAAtCBXPIwZpyfTqXB0AgFRgwVkcqwdswCvsSkdutcWnZHA9un0BsMxpNprN9Dcfn8KIkAVggSCwZDobD0gikSiYejMTi8QoCcTSdg8PBKcraQhePBmWzMJyoNz4HyBcAhSKxbwJdLZXBNArY7wE6qTujNVsdbs5AoDs4UOgY-gynqZNQ4BhkDB8NVavUKuEFjdqHdzZ1LS8be97V9J78Vq6ktoPRBgaDwVCYXCA8jUSGsbj8SBCSSO4r4zSa8nU+yM1mc1VBcKoKLxTApTK5XLRUqwfOl1XrbVqF1XJqANFRuxgth+0HYcajqBoJwiKd4BnDoXEeHwrVeW0PgdJ0lnXIA)\r\n[Playground link with relevant code (tuple variant)](https://www.typescriptlang.org/play?ts=5.1.0-dev.20230227#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVIB4AVeEADwxFWAGd40BrVHAd1QG0BdAPgAoAoePFgBzAFzx2gofAB08gN7SZkgNLws+BiACeORPCKcJSlSoAOMHMGRgQE3qgk0MMTSICU8ALzdD7VU4AbmUzMDwaZABbe3heMgkiAM4vX3gANxwsYBCzeABfXJl86U5+DwlM7JCAehr4AHUcGAYafkReKSFTGUtrW1jeVL8AIgALEAgIHBGAGlDw1EiYhzJh+DJZDBwAGVYQGABhKBoQIfmhfPmU2vqmlraOrvgeoT6bOwcneBc3VE8fH5UBcZItloM1oCNltdvsjiczh4QVd+Dd+HUftgpvBgDgQDRUAByDDwFjNBizUjpKikrAYMbwEYASSifWpwHgADE0JhcPgmahEAcqHYNPgAPIAIwAVuAMHQoNR4ABZED06w0EbCBhQMWuKAAWnIlnxND5YqFcHQCDNlEenWkr3g7wGX3WwIWEWiEPWm22exYB2Op3O0hRaIxLiw2Nx+KJJLJLUpIGp+BYdIZzNZVnZXJ52Dw8AFlpFCE08ClsswCqVqvVtC1UB1epghuNcBoZsLmhL1p+dPx7Qd3VCLs+SHz5qGL1CQjgGGQMHw40m0xGRUuIKEYO9q19MIDQYRoc3qI8t0x0YgOLxBOJpPJydTtPpjJZbJAHO56AL-MFwr7ctKzlGsOTrMYNUbZtNH1I0yBNTtzR7ADRVtQcnkdUcrA+REZzyedF2XCYphmDcCi3eAdxWOJITSP1YUDeEQyRMNrnPfggA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ndeclare function f\u003cT>(\r\n arg: {\r\n [K in keyof T]: {\r\n produce: (n: string) => T[K];\r\n consume: (x: T[K]) => void;\r\n };\r\n }\r\n): void;\r\n// Works\r\nf({\r\n a: {\r\n produce: () => \"hello\",\r\n consume: (x) => x.toLowerCase(),\r\n },\r\n});\r\n// Works\r\nf({\r\n a: {\r\n produce: (n: string) => n,\r\n consume: (x) => x.toLowerCase(),\r\n },\r\n});\r\n// still doesn't work, even with \"Improved Function Inference in Objects and Methods\" aka intra-expression inference sites\r\nf({\r\n a: {\r\n produce: (n) => n,\r\n consume: (x) => x.toLowerCase(),\r\n },\r\n});\r\n// still doesn't work, even with \"Improved Function Inference in Objects and Methods\" aka intra-expression inference sites\r\nf({\r\n a: {\r\n produce: function () {\r\n return \"hello\";\r\n },\r\n consume: (x) => x.toLowerCase(),\r\n },\r\n});\r\n// still doesn't work, even with \"Improved Function Inference in Objects and Methods\" aka intra-expression inference sites\r\nf({\r\n a: {\r\n produce() {\r\n return \"hello\";\r\n },\r\n consume: (x) => x.toLowerCase(),\r\n },\r\n});\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nThis kind of inference that was improved in https://github.com/microsoft/TypeScript/pull/48538 doesn't work within a reverse mapped type.\r\n\r\n### 🙂 Expected behavior\r\n\r\nIt should work in the same way as it does outside of the reverse mapped type. The code in the playground is almost literally taken from the 4.7 announcement blog post about this improvement ([here](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html#improved-function-inference-in-objects-and-methods)). The only difference is that the `produce`/`consume` \"pair\" is within a property of reverse mapped type\r\n\r\n---\r\n\r\nPart of the problem is likely in that `inferReverseMappedType` calls `inferTypes` with separate `inferences` here:\r\nhttps://github.dev/microsoft/TypeScript/blob/e2283e99b47942b863d016c65a3e430dca1549b9/src/compiler/checker.ts#L23938-L23939\r\nand that is not linked anyhow to the current inference `context` and `inferFromIntraExpressionSites` tries to infer this kind of stuff from `context.intraExpressionInferenceSites`+`context.inferences` and the latter won't be present for the computed reverse mapped type inference:\r\nhttps://github.dev/microsoft/TypeScript/blob/e2283e99b47942b863d016c65a3e430dca1549b9/src/compiler/checker.ts#L23756-L23763\r\n\r\nHowever, I also noticed that `inferReverseMappedType` is not called **at all** in this case so those inferences for it aren't even gathered in the first place.\r\n\r\n","author":{"url":"https://github.com/Andarist","@type":"Person","name":"Andarist"},"datePublished":"2023-02-28T11:29:03Z","url":"https://github.com/microsoft/TypeScript/issues/53018"}
| 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:5eff49bb-555f-4726-0231-d4210712cbfb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C478:3DD488:8E9152:B650F6:6B00ED24 |
| html-safe-nonce | 183106f8b12f7a5097b89a0d595ad163818a4714ed0dbca59e8eadd274338236 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDc4OjNERDQ4ODo4RTkxNTI6QjY1MEY2OjZCMDBFRDI0IiwidmlzaXRvcl9pZCI6IjgyMzYyNDQ2ODEyMTQ3MTcyMjAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 759f1cf8641cc03a60670807d51e15837d00d974edb9f3bb3d6b5b4c9ec12794 |
| hovercard-subject-tag | issue:1602864357 |
| 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/53018/issue_layout |
| twitter:image | https://opengraph.githubassets.com/29196c20915ae9e765af98935f3e64f1fd758a0df2ac537da48ee3069ea1ff24/microsoft/TypeScript/issues/53018 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/29196c20915ae9e765af98935f3e64f1fd758a0df2ac537da48ee3069ea1ff24/microsoft/TypeScript/issues/53018 |
| og:image:alt | Bug Report 🔎 Search Terms intra expression inference reverse mapped type 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link Playground link with rele... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Andarist |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width