Title: Circular mapped property is treated as missing when selecting contextual type from intersections · Issue #64534 · microsoft/TypeScript · GitHub
Open Graph Title: Circular mapped property is treated as missing when selecting contextual type from intersections · Issue #64534 · microsoft/TypeScript
X Title: Circular mapped property is treated as missing when selecting contextual type from intersections · Issue #64534 · microsoft/TypeScript
Description: 🔎 Search Terms circular mapped property contextual type intersection index signature reverse mapped type isCircularMappedProperty 🕗 Version & Regression Information This changed in commit or PR #52095 ⏯ Playground Link No response 💻 Code...
Open Graph Description: 🔎 Search Terms circular mapped property contextual type intersection index signature reverse mapped type isCircularMappedProperty 🕗 Version & Regression Information This changed in commit or PR #52...
X Description: 🔎 Search Terms circular mapped property contextual type intersection index signature reverse mapped type isCircularMappedProperty 🕗 Version & Regression Information This changed in commit or PR...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/64534
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Circular mapped property is treated as missing when selecting contextual type from intersections","articleBody":"### 🔎 Search Terms\n\ncircular mapped property contextual type intersection index signature reverse mapped type isCircularMappedProperty\n\n### 🕗 Version & Regression Information\n\n- This changed in commit or PR #52095\n\n### ⏯ Playground Link\n\n_No response_\n\n### 💻 Code\n\n```ts\ntype Func\u003cT> = () => T;\ntype Mapped\u003cT> = { [K in keyof T]: Func\u003cT[K]> };\n\ntype Indexed = {\n [key: string]: () => 0 | 1;\n};\n\ndeclare function reproduce(options: number): void;\ndeclare function reproduce\u003cT>(options: Mapped\u003cT> & Indexed): T;\n\nexport const result = reproduce({\n name: () => 0\n});\n```\n\n### 🙁 Actual behavior\n\nThe call is accepted.\n\nThe inferred declaration is:\n\n```ts\nexport declare const result: {\n name: 0;\n};\n```\n\nDuring contextual typing, lookup of the `name` property through the reverse-mapped `Mapped\u003cT>` constituent reaches the circular mapped-property guard, so `getTypeOfConcretePropertyOfContextualType` does not produce a contextual property type from that constituent.\n\nThe intersection-specific contextual typing logic introduced in #52095 can then consider applicable index information from other constituents. In this example, the index signature from `Indexed` provides `() => 0 | 1` as the contextual type of `name`.\n\nThat contextual type preserves the returned `0` as a literal type, which allows reverse inference to infer:\n\n```ts\nT = {\n name: 0;\n}\n```\n\nand the call succeeds.\n\nBefore #52095, the same code reports TS2769 because no index-signature contextual type is supplied in this situation. As a result, `() => 0` is inferred as `() => number`, which is not assignable to `() => 0 | 1`.\n\nThere appear to be two potentially separate questions here:\n\n1. Whether this reverse-mapped `name` property should reach the circular mapped-property guard at all.\n2. If the circularity guard does apply, whether the resulting lack of a concrete contextual property type should allow the intersection logic to fall back to an index signature in the same way as when no concrete property exists.\n\n### 🙂 Expected behavior\n\nI am not certain that the pre-#52095 TS2769 result is necessarily the desired behavior for this particular reproduction, since the currently inferred result is sound.\n\nWhat seems unclear is whether the interaction between circular mapped-property handling and the index-info fallback introduced in #52095 is intentional.\n\nIn particular, these situations currently become indistinguishable to the subsequent intersection contextual-typing logic:\n\n1. no concrete contextual property type is found because the property is absent\n2. no concrete contextual property type is produced because property resolution was suppressed by the circular mapped-property guard\n\nIf those cases are intentionally meant to permit the same index-info fallback, then the current behavior is expected.\n\nOtherwise, either:\n\n- the reverse-mapped property may be reaching the circularity guard when it should not, or\n- the reason that concrete property lookup produced no type may need to be preserved so that the intersection logic can distinguish circularity suppression from actual property absence.\n\nThe main question is therefore whether this interaction is intentional.\n\n### Additional information about the issue\n\nI found this while investigating my PR #64502, which deals with a different circular contextual-typing issue involving static properties.\n\nWhile tracing contextual property lookup and circularity handling, I noticed that this reproduction reaches a path where lookup of the reverse-mapped property is suppressed by the circular mapped-property check, after which the intersection logic introduced by #52095 uses an applicable index signature as the contextual type.\n\nI narrowed the observable behavior change down to #52095.\n\nTested revisions:\n\n- `6894ff7f38211589f0f41f8383727c57144857e1` (parent of #52095):\n reports TS2769\n- `e6edc567a3946d203436265c5b525817fe2f708d` (#52095):\n no error\n\n#38653 introduced the behavior where contextual typing does not attempt to resolve a mapped property when doing so would cause circular type resolution.\n\n#52095 later refactored contextual property lookup for intersections. When `getTypeOfConcretePropertyOfContextualType` does not produce a type for a constituent, the intersection logic may consider applicable index information unless a concrete property type is found elsewhere.\n\nI instrumented the current checker locally and confirmed that this reproduction reaches the path where contextual typing through the reverse-mapped property is suppressed by the circularity check and the index signature from the other intersection constituent is subsequently used as the contextual type.\n\nI also tested the current checker with that index-signature fallback temporarily suppressed for this case. With the fallback suppressed, the reproduction reports TS2769, matching the behavior from immediately before #52095.\n\nAt this point, I don't know whether the defect is specifically in the index-info fallback.\n\nIt may instead be that this reverse-mapped property should not be classified as circular at this stage.\n\nThe interesting interaction is that a lookup suppressed by the circularity guard and a lookup where no concrete property is available can both result in no concrete contextual property type being returned, while the subsequent intersection logic does not appear to distinguish why that happened.","author":{"url":"https://github.com/Fugu0141","@type":"Person","name":"Fugu0141"},"datePublished":"2026-09-29T16:21:05Z","url":"https://github.com/microsoft/TypeScript/issues/64534"}
| 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:a443df81-d0c0-041d-8af9-f5aa7173b244 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E388:10D9F8:B24A8B:ED1037:6B00EBE4 |
| html-safe-nonce | bc4151f7e54f8d07292db7ca68d80ed9dc0ebbb471dad03530c984fa2f0b7a0f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzg4OjEwRDlGODpCMjRBOEI6RUQxMDM3OjZCMDBFQkU0IiwidmlzaXRvcl9pZCI6Ijk3NTc3NDc2ODUyOTczMDUzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 44c83a4cfbecf6aca02ef14682c9367bd231e956c364f7c29248bdb3ab972c86 |
| hovercard-subject-tag | issue:5633636599 |
| 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/64534/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eb9311de8e299a88414340007ffde743662d9bbf124b24dbb92316e04a8d33d9/microsoft/TypeScript/issues/64534 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eb9311de8e299a88414340007ffde743662d9bbf124b24dbb92316e04a8d33d9/microsoft/TypeScript/issues/64534 |
| og:image:alt | 🔎 Search Terms circular mapped property contextual type intersection index signature reverse mapped type isCircularMappedProperty 🕗 Version & Regression Information This changed in commit or PR #52... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Fugu0141 |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width