Title: Key in mapped type not traversed when there's a something-with-generics extends clause in it · Issue #62370 · microsoft/TypeScript · GitHub
Open Graph Title: Key in mapped type not traversed when there's a something-with-generics extends clause in it · Issue #62370 · microsoft/TypeScript
X Title: Key in mapped type not traversed when there's a something-with-generics extends clause in it · Issue #62370 · microsoft/TypeScript
Description: 🔎 Search Terms mapped conditional type keyof generic extends ternary 🕗 Version & Regression Information This changed between versions 4.0.5 and 4.1.5 (Because the mapped type wouldn't work prior to 4.1) ⏯ Playground Link https://www.type...
Open Graph Description: 🔎 Search Terms mapped conditional type keyof generic extends ternary 🕗 Version & Regression Information This changed between versions 4.0.5 and 4.1.5 (Because the mapped type wouldn't work prior to...
X Description: 🔎 Search Terms mapped conditional type keyof generic extends ternary 🕗 Version & Regression Information This changed between versions 4.0.5 and 4.1.5 (Because the mapped type wouldn't work ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/62370
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Key in mapped type not traversed when there's a something-with-generics extends clause in it","articleBody":"### 🔎 Search Terms\n\nmapped conditional type keyof generic extends ternary\n\n### 🕗 Version & Regression Information\n\n- This changed between versions 4.0.5 and 4.1.5\n(Because the mapped type wouldn't work prior to 4.1)\n\n### ⏯ Playground Link\n\nhttps://www.typescriptlang.org/play/?ts=5.9.2#code/KYDwDg9gTgLgBDAnmYcCyBDMKAmAVCPKDAN2CgGdgcAePAPjgF4BYAKDjgG93POBtANJwAlgDs4Aa2CIIAMzh44GCoqEBdOKBjAxOVRjGI4AfjjCAXOfVWA5DGJlK1W7zgBfduyQo4ACQgnPAALEQoARmZ0LFwCIlJyKloeDmUjAAUoCDArQ0Q3CgdM7KtCqHEAczcIACMAK2KcuFq64ABjGHZ3enYAel64QBRyQHg-5QAbMbgwLJRYEWADKFQxCAB3OAAiBwTnHA2LPoGfVACg0IiolP6+TjzGqy3HROoNgG5Dm7gy+83tpyS3h8bi0fo8dgD3mxrp42N5kCdAuQQmEAEx0RhMaLYahxJ67GgpW4ZGa5IwFIokr4OSrVeo-PBdHpQgaAGXJmnSZqJVABbMIUSoHZkIeH+RFQZEUNEMS5Avh3Slg-4vSHXG7fBV-Z57FUDGFw3ynJHnADM6KimGx+EIeKSBLc8pKaXyqXVjrKNNSIMpACV2tBaNJZAo8AAaOBiACu3Jq5CZ3Q+bK92S5cF5FH5Ygqguux1FZzCpulmKuAxuDqaiq1gKFaopjsru2r0KAA\n\n### 💻 Code\n\n```ts\nexport type MappedToTraversed\u003cT> =\n {\n [K in keyof T as T[K] extends any ? K : K]: 'traversed'\n }\n\ntype HoverThis1 = MappedToTraversed\u003c{\n anyProp: any\n strProp: string\n objProp: object\n}>\n// ✔️ all properties are now \"traversed\":\n// type HoverThis1 = {\n// anyProp: \"traversed\";\n// strProp: \"traversed\";\n// objProp: \"traversed\";\n// }\n\ntype HoverThis2\u003cT> = MappedToTraversed\u003c{\n anyProp: any\n strProp: string\n objProp: T\n}>\n// ❌ objProp is missing:\n// type HoverThis2\u003cT> = {\n// anyProp: \"traversed\";\n// strProp: \"traversed\";\n// }\n\ntype HoverThis3\u003cT> = MappedToTraversed\u003c{\n anyProp: any\n strProp: string\n objProp: Record\u003ckeyof T, number>\n}>\n// ❌ objProp is missing:\n// type HoverThis3\u003cT> = {\n// anyProp: \"traversed\";\n// strProp: \"traversed\";\n// }\n```\n\n\n### 🙁 Actual behavior\n\nThe `objProp` is missing from the `HoverThis` types when it is somehow using a generic (e.g. when used as property type or key in a `Record`). Looks like it is not being traversed during mapping at all due to the extends clause, because the ternary `as T[K] extends any ? K : K` should IMHO always evaluate to `K`.\n\n### 🙂 Expected behavior\n\n`objProp` should be listed in all `HoverThis` types.\n\n### Additional information about the issue\n\nI think it's due to the `extends` clause, because if the mapping is simply written as\n\n```ts\nexport type MappedToTraversed\u003cT> =\n {\n [K in keyof T as K]: 'traversed'\n }\n```\n\n`objProp` is listed in the resulting `HoverThis` types.\n\nIt also fails if\n- the ternary is the other way round, i.e. `any extends T[K] ? K : K`\n- the ternary checks something that should always be true `T[K] extends T[K] ? K : K`\n- I try to disable union distribution according to hand book: `[T[K]] extends [any] ? K : K`\n\nHowever, if I mess up disabling the union distribution (putting only one side in square brackets), it works..? `[T[K]] extends any ? K : K`. This feels like an unsafe workaround.","author":{"url":"https://github.com/Holzchopf","@type":"Person","name":"Holzchopf"},"datePublished":"2025-09-01T08:09:37Z","url":"https://github.com/microsoft/TypeScript/issues/62370"}
| 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:6d7b6796-ed2f-06a9-5333-c72c3fa2e474 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8778:399E4B:1678B56:1DD77B8:6B013669 |
| html-safe-nonce | a12b23d8e38ced94b39e5687635609565bd80782e0a89f28842ef55cc0ff57db |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Nzc4OjM5OUU0QjoxNjc4QjU2OjFERDc3Qjg6NkIwMTM2NjkiLCJ2aXNpdG9yX2lkIjoiMjMxODE4NTQzNzA1MjYxNDI1MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6966cae8aaae244ef1198aff96b3c2c364a724a3662f6a8c2c43e8fb47f1a3b3 |
| hovercard-subject-tag | issue:3371687215 |
| 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/62370/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fcf26d525101cc1af7d8965488defd834357c84f604b3a9ddd455a0cc78c3559/microsoft/TypeScript/issues/62370 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fcf26d525101cc1af7d8965488defd834357c84f604b3a9ddd455a0cc78c3559/microsoft/TypeScript/issues/62370 |
| og:image:alt | 🔎 Search Terms mapped conditional type keyof generic extends ternary 🕗 Version & Regression Information This changed between versions 4.0.5 and 4.1.5 (Because the mapped type wouldn't work prior to... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Holzchopf |
| 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