Title: TS not able to infer that T[PropsThatExtend
Open Graph Title: TS not able to infer that T[PropsThatExtend
X Title: TS not able to infer that T[PropsThatExtend
Description: Bug Report 🔎 Search Terms type inference mapped type conditional types 🕗 Version & Regression Information All versions I tested. ⏯ Playground Link Playground link with relevant code 💻 Code type PropsThatExtend
Open Graph Description: Bug Report 🔎 Search Terms type inference mapped type conditional types 🕗 Version & Regression Information All versions I tested. ⏯ Playground Link Playground link with relevant code 💻 Code type Pro...
X Description: Bug Report 🔎 Search Terms type inference mapped type conditional types 🕗 Version & Regression Information All versions I tested. ⏯ Playground Link Playground link with relevant code 💻 Code type...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/42795
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TS not able to infer that T[PropsThatExtend\u003cT, M>] extends M","articleBody":"# Bug Report\r\n\r\n### 🔎 Search Terms\r\n\r\n- type inference\r\n- mapped type\r\n- conditional types\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nAll versions I tested.\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.2.0-beta#code/C4TwDgpgBACgTgezAZwCoAsCGwCiAPYCAOwBMAeVAGigFkA+KAXigG8AoKKAbQGkoBLIlADWEEAgBmUVAF0AXNN4yoEAsRLJaUAPxQ+CohABuEOAG42AXy6jxU2RbYBjBEWTAByAGIIArnCYoCko6AAoEACMAKwUqKDBEMAV4JDQsXDVSYKgiXwBbCNM6AEomBnZOOAhgfyFIqK4EpGVGVqgAFgtLNjZQSCgfBECKqAjMOAN8wvMOUcwAL0mC0ygAHyh3OEEAcwtOAEdfPAUAJjWOrscAegAqWES07HxCLMHqXOW4BlbmACIxuC-c6-Q54X5mKA3K49fjePxwUIsOYTKAARmoY0WUBO1FBCnaUEsUEwmjeUBBR1+xTMQA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ntype PropsThatExtend\u003cT, M> = {\r\n [K in keyof T]: T[K] extends M ? K : never;\r\n}[keyof T];\r\n\r\nconst isFour = \u003cT,>(obj: T, prop: PropsThatExtend\u003cT, number>) => {\r\n return obj[prop] === 4;\r\n}\r\n\r\ntype Foo = {\r\n bar: number;\r\n baz: number | string;\r\n qux: 2 | 4;\r\n};\r\n\r\n/* PropsThatExtend\u003cFoo, number> === \"bar\" | \"qux\"; */\r\n\r\nisFour({ bar: 1, baz: 2, qux: 4 } as Foo, \"qux\");\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nError on line 6:\r\n`This condition will always return 'false' since the types 'T[PropsThatExtend\u003cT, number>]' and 'number' have no overlap.`\r\n\r\n### 🙂 Expected behavior\r\n\r\nSince all members in `T[PropsThatExtend\u003cT, number>]` extend `number` the compiler should be able to recognize that the two types being compared overlap.\r\n","author":{"url":"https://github.com/Flonk","@type":"Person","name":"Flonk"},"datePublished":"2021-02-14T01:51:07Z","url":"https://github.com/microsoft/TypeScript/issues/42795"}
| 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:0850653a-a303-22b6-797a-4aa3d410864e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 88E4:33444D:29C9325:3794F0B:6B01BD4D |
| html-safe-nonce | 6e6b5b34ea426c062f58c40a2e5d4116ce7aa844131c07400aa7b3e4bcc756b9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OEU0OjMzNDQ0RDoyOUM5MzI1OjM3OTRGMEI6NkIwMUJENEQiLCJ2aXNpdG9yX2lkIjoiNzUzMDY2OTMwNDk1ODc5NTA4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0bf8c6066876c55a18dafa5c162b68a2c080f1f2402021ceb0aa206a12e586af |
| hovercard-subject-tag | issue:807869128 |
| 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/42795/issue_layout |
| twitter:image | https://opengraph.githubassets.com/234c6717e78f287920334aadaecd2abfa61bd820af61624b87986990da29bc32/microsoft/TypeScript/issues/42795 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/234c6717e78f287920334aadaecd2abfa61bd820af61624b87986990da29bc32/microsoft/TypeScript/issues/42795 |
| og:image:alt | Bug Report 🔎 Search Terms type inference mapped type conditional types 🕗 Version & Regression Information All versions I tested. ⏯ Playground Link Playground link with relevant code 💻 Code type Pro... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Flonk |
| 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