Title: Computed type key inference inconsistent with identical explicitly declared type · Issue #59987 · microsoft/TypeScript · GitHub
Open Graph Title: Computed type key inference inconsistent with identical explicitly declared type · Issue #59987 · microsoft/TypeScript
X Title: Computed type key inference inconsistent with identical explicitly declared type · Issue #59987 · microsoft/TypeScript
Description: 🔎 Search Terms keyof required keys key evaluation reduce getReducedType 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link https://tsplay.dev/WKQkzN 💻 Code type distilled = distill<{ // ^? ...
Open Graph Description: 🔎 Search Terms keyof required keys key evaluation reduce getReducedType 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link https://tsplay.dev/WKQkzN ...
X Description: 🔎 Search Terms keyof required keys key evaluation reduce getReducedType 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link https://tsplay.dev/WKQ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/59987
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Computed type key inference inconsistent with identical explicitly declared type","articleBody":"### 🔎 Search Terms\n\nkeyof required keys key evaluation reduce getReducedType\n\n### 🕗 Version & Regression Information\n\n- This is the behavior in every version I tried\r\n\r\n\n\n### ⏯ Playground Link\n\nhttps://tsplay.dev/WKQkzN\n\n### 💻 Code\n\n```ts\r\ntype distilled = distill\u003c{\r\n\t// ^?\r\n\tfoo: \"default\"\r\n\tbar?: number\r\n}>\r\n\r\n// incorrectly inferred as unknown\r\ntype requiredDistilledKey = requiredKeyOf\u003cdistilled>\r\n// ^?\r\n\r\n// explicit declaration identical to hover of distilled\r\ntype declared = {\r\n\tbar?: number\r\n} & {\r\n\tfoo?: \"default\"\r\n}\r\n\r\n// now correctly inferred as never\r\ntype requiredDeclaredKey = requiredKeyOf\u003cdeclared>\r\n// ^?\r\n\r\ntype requiredKeyOf\u003co> = {\r\n\t[k in keyof o]-?: o extends { [_ in k]-?: o[k] } ? k : never\r\n}[keyof o]\r\n\r\ntype distill\u003ct> = t extends object ? distillMappable\u003ct> : t\r\n\r\ntype distillMappable\u003co> = {\r\n\t[k in keyof o as k extends inferredDefaultKeyOf\u003co> ? never : k]: distill\u003co[k]>\r\n} & {\r\n\t[k in inferredDefaultKeyOf\u003co>]?: distill\u003co[k]>\r\n}\r\n\r\ntype inferredDefaultKeyOf\u003co> = {\r\n\t[k in keyof o]: o[k] extends \"default\" ? k : never\r\n}[keyof o]\r\n\r\n\r\n```\r\n\n\n### 🙁 Actual behavior\n\n`requiredDistilledKey` inferred as `unknown`\n\n### 🙂 Expected behavior\n\n`requiredDistilledKey` inferred as `never`, consistent with the equivalent declared version\n\n### Additional information about the issue\n\n_No response_","author":{"url":"https://github.com/ssalbdivad","@type":"Person","name":"ssalbdivad"},"datePublished":"2024-09-17T09:38:30Z","url":"https://github.com/microsoft/TypeScript/issues/59987"}
| 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:c8fb1798-6494-99cc-4bcb-61ae626611fa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A860:5028D:622B2B:7E8880:6B05013C |
| html-safe-nonce | 69c104c13963288c48e6e5c421506ea87f1fef0dd38335a2a19f68a43e54db14 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODYwOjUwMjhEOjYyMkIyQjo3RTg4ODA6NkIwNTAxM0MiLCJ2aXNpdG9yX2lkIjoiMjY2MjM5NTYyMjM3MTY4ODc2NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3840037d7c5b54df29f1a93f529ce4dc365c997b5157a47bbe90b0a2666c6b88 |
| hovercard-subject-tag | issue:2530610924 |
| 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/59987/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1d861ececaded234827e17bb29d77f8fadf711024f3683f487296f585e4afab8/microsoft/TypeScript/issues/59987 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1d861ececaded234827e17bb29d77f8fadf711024f3683f487296f585e4afab8/microsoft/TypeScript/issues/59987 |
| og:image:alt | 🔎 Search Terms keyof required keys key evaluation reduce getReducedType 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link https://tsplay.dev/WKQkzN ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ssalbdivad |
| hostname | github.com |
| expected-hostname | github.com |
| None | 854d880890b5e847b3fce9d1b31f032107baeddeebad2aa379c48aa4f1451f6b |
| 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 | 220e980097d94ce616d5d11fbd5316d208e3fc93 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width