Title: The evaluation of the Keyof Type Operator produces different results to the Pick built-in tool. · Issue #48173 · microsoft/TypeScript · GitHub
Open Graph Title: The evaluation of the Keyof Type Operator produces different results to the Pick built-in tool. · Issue #48173 · microsoft/TypeScript
X Title: The evaluation of the Keyof Type Operator produces different results to the Pick built-in tool. · Issue #48173 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms Pick 🕗 Version & Regression Information v4.5.4 ⏯ Playground Link Link 💻 Code interface User { name?: string age?: number address?: string } type Foo
Open Graph Description: Bug Report 🔎 Search Terms Pick 🕗 Version & Regression Information v4.5.4 ⏯ Playground Link Link 💻 Code interface User { name?: string age?: number address?: string } type Foo
X Description: Bug Report 🔎 Search Terms Pick 🕗 Version & Regression Information v4.5.4 ⏯ Playground Link Link 💻 Code interface User { name?: string age?: number address?: string } type Foo<T, U = keyof T&...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/48173
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"The evaluation of the Keyof Type Operator produces different results to the Pick built-in tool.","articleBody":"# Bug Report\r\n\r\n\u003c!--\r\n Please fill in each section completely. Thank you!\r\n--\u003e\r\n\r\n### 🔎 Search Terms\r\nPick\r\n\u003c!--\r\n What search terms did you use when trying to find an existing bug report?\r\n List them here so people in the future can find this one more easily.\r\n--\u003e\r\n\r\n### 🕗 Version \u0026 Regression Information\r\nv4.5.4\r\n\r\n\r\n\r\n\u003c!-- When did you start seeing this bug occur?\r\n\r\n\"Bugs\" that have existed in TS for a long time are very likely to be FAQs; refer to\r\n https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs\r\n\r\nIf possible, please try testing the nightly version of TS to see if it's already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n\r\nNote: The TypeScript Playground can be used to try older versions of TypeScript.\r\n\r\nPlease keep and fill in the line that best applies:\r\n--\u003e\r\n\r\n\r\n### ⏯ Playground Link\r\n[Link](https://www.typescriptlang.org/play?ts=4.5.4#code/JYOwLgpgTgZghgYwgAgKoGdrIN4ChnIhwC2EA-AFzLphSgDm+yc95VIArsQEbRNwATAVAjp0larQa4AvrlxgAngAcUAMQD2GgDwAVADRpkAXmQBrCIo0xkugHwmcTANoAFZKGQBRAB61EYNqohhZWNvYAulS6bhGy8goqKABCcFB6+qjGoda2DqYAShAAjhzAIgLarsAIZhneflABQSGWufZ2dglKqshF6I6aOhjQhgDkRKRjDgQEAPRzkxBUNHQg9MgAPsgcIAIQMKAQAgDcib39AEyOqekjUONL07MLSytS60A)\r\n\u003c!--\r\n A link to a TypeScript Playground \"Share\" link which shows this behavior\r\n\r\n The TypeScript Workbench can be used for more complex setups, try\r\n https://www.typescriptlang.org/dev/bug-workbench/\r\n\r\n As a last resort, you can link to a repo, but these will be slower for us to investigate.\r\n--\u003e\r\n\r\n\r\n### 💻 Code\r\n```lang=ts\r\ninterface User {\r\n name?: string\r\n age?: number\r\n address?: string\r\n}\r\n\r\ntype Foo\u003cT, U = keyof T\u003e = {\r\n [P in Extract\u003cU, keyof T\u003e]: T[P]\r\n}\r\n\r\ntype Bar\u003cT,U=keyof T\u003e = Required\u003cPick\u003cT, Extract\u003cU, keyof T\u003e\u003e\u003e\r\n\r\ntype Res = Foo\u003cUser, 'name'\u003e //name: string | undefined;\r\ntype Res2 = Bar\u003cUser, 'name'\u003e //name: string\r\n```\r\n\u003c!-- Please post the relevant code sample here as well--\u003e\r\n```ts\r\n// We can quickly address your report if:\r\n// - The code sample is short. Nearly all TypeScript bugs can be demonstrated in 20-30 lines of code!\r\n// - It doesn't use external libraries. These are often issues with the type definitions rather than TypeScript bugs.\r\n// - The incorrectness of the behavior is readily apparent from reading the sample.\r\n// Reports are slower to investigate if:\r\n// - We have to pare too much extraneous code.\r\n// - We have to clone a large repo and validate that the problem isn't elsewhere.\r\n// - The sample is confusing or doesn't clearly demonstrate what's wrong.\r\n```\r\n\r\n### 🙁 Actual behavior\r\n```\r\ntype Res = Foo\u003cUser, 'name'\u003e //name: string | undefined;\r\n```\r\nThe value evaluated for the name contains undefined\r\n\u003c!-- What happened, and why it was wrong --\u003e\r\n\r\n### 🙂 Expected behavior\r\n\r\n```\r\ntype Foo\u003cT, U = keyof T\u003e = {\r\n [P in Extract\u003cU, keyof T\u003e]: T[P]\r\n}\r\n```\r\n[P in Extract\u003cU, keyof T\u003e]: T[P] should not return undefined because Extract only narrows down the range of the keys\r\n\r\n\u003c!-- What you expected to happen instead, and why --\u003e\r\n","author":{"url":"https://github.com/someBrown","@type":"Person","name":"someBrown"},"datePublished":"2022-03-08T08:09:19.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/48173/TypeScript/issues/48173"}
| 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:a166da68-f371-51db-769b-01c22cddc086 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 86E2:A3BF2:126E1D8:1947689:6A61B872 |
| html-safe-nonce | f6516b6960b7084958b0759ae6591b485376bf7569559f5b98109e217a42c9d4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NkUyOkEzQkYyOjEyNkUxRDg6MTk0NzY4OTo2QTYxQjg3MiIsInZpc2l0b3JfaWQiOiIyODQ4MDc4MzYyOTIwOTkwODM0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 9146566882c0de0f062dd59e1fcc55be3f359aea277b2a895da79e50acb5e36e |
| hovercard-subject-tag | issue:1162346184 |
| 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/48173/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ea15a7ff1ad1d696b10b417f8e97586db5ecd939011dc6c3f059dd711dff6cdd/microsoft/TypeScript/issues/48173 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ea15a7ff1ad1d696b10b417f8e97586db5ecd939011dc6c3f059dd711dff6cdd/microsoft/TypeScript/issues/48173 |
| og:image:alt | Bug Report 🔎 Search Terms Pick 🕗 Version & Regression Information v4.5.4 ⏯ Playground Link Link 💻 Code interface User { name?: string age?: number address?: string } type Foo |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | someBrown |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6f4633bcf01c1ad14b73fd07dd39ac31d61f3d3c2578ee08ec1792b7b351eeb9 |
| 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 | ac296ae7f21856f1f92adbad22f870b6fbb4b907 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width