Title: Filtering keys by property type doesn't narrow the actual property types · Issue #28111 · microsoft/TypeScript · GitHub
Open Graph Title: Filtering keys by property type doesn't narrow the actual property types · Issue #28111 · microsoft/TypeScript
X Title: Filtering keys by property type doesn't narrow the actual property types · Issue #28111 · microsoft/TypeScript
Description: TypeScript Version: 3.2.0-dev.20181023 Search Terms: keyof, filter, type is not assignable to type Code type WantedTypes = string | number type WantedKeys
Open Graph Description: TypeScript Version: 3.2.0-dev.20181023 Search Terms: keyof, filter, type is not assignable to type Code type WantedTypes = string | number type WantedKeys
X Description: TypeScript Version: 3.2.0-dev.20181023 Search Terms: keyof, filter, type is not assignable to type Code type WantedTypes = string | number type WantedKeys<T> = { [K in keyof T]: T[K] extends ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/28111
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Filtering keys by property type doesn't narrow the actual property types","articleBody":"**TypeScript Version:** 3.2.0-dev.20181023\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:**\r\nkeyof, filter, type is not assignable to type\r\n\r\n**Code**\r\n\r\n```ts\r\ntype WantedTypes = string | number\r\n\r\ntype WantedKeys\u003cT> = { [K in keyof T]: T[K] extends WantedTypes ? K : never }[keyof T]\r\n\r\nfunction foo\u003cT> (obj: T, key: WantedKeys\u003cT>): WantedTypes {\r\n return obj[key]\r\n}\r\n\r\nclass DerivedProperty\u003cT extends WantedTypes> { }\r\n\r\ntype Derived\u003cT> = {\r\n [K in WantedKeys\u003cT>]: DerivedProperty\u003cT[K]>\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nCompiles without errors.\r\n\r\n**Actual behavior:**\r\n```\r\ntest.ts:6:5 - error TS2322: Type 'T[{ [K in keyof T]: T[K] extends string | number ? K : never; }[keyof T]]' is not assignable to type 'string | number'.\r\n Type 'T[{ [K in keyof T]: T[K] extends string | number ? K : never; }[keyof T]]' is not assignable to type 'number'.\r\n\r\n6 return obj[key]\r\n ~~~~~~~~~~~~~~~\r\n\r\ntest.ts:12:43 - error TS2344: Type 'T[K]' does not satisfy the constraint 'string | number'.\r\n Type 'T[K]' is not assignable to type 'number'.\r\n\r\n12 [K in WantedKeys\u003cT>]: DerivedProperty\u003cT[K]>\r\n ~~~~\r\n```\r\n\r\nI couldn't find any similar issues here.","author":{"url":"https://github.com/the-ress","@type":"Person","name":"the-ress"},"datePublished":"2018-10-24T20:03:17Z","url":"https://github.com/microsoft/TypeScript/issues/28111"}
| 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:586b0d43-b685-0d25-c4b3-4d6b081b06d2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EDA8:62F48:5A11C6:7788C8:6B01D153 |
| html-safe-nonce | e89c62773b32f4a4cb69ac1d000c533711d64625248f7ba1cbcd16a7089709a8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFREE4OjYyRjQ4OjVBMTFDNjo3Nzg4Qzg6NkIwMUQxNTMiLCJ2aXNpdG9yX2lkIjoiNTQ4OTg5NTUxNTI5MjI5MTQxMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5b99fdc427f22f4b3c1039df31470c3fc5673942af475f9297dcf5f279b1a985 |
| hovercard-subject-tag | issue:373654309 |
| 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/28111/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5dbe7f05118a5d2fffa47ec704e0871f940e0212a65d378e5b5e7eb1696ebb27/microsoft/TypeScript/issues/28111 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5dbe7f05118a5d2fffa47ec704e0871f940e0212a65d378e5b5e7eb1696ebb27/microsoft/TypeScript/issues/28111 |
| og:image:alt | TypeScript Version: 3.2.0-dev.20181023 Search Terms: keyof, filter, type is not assignable to type Code type WantedTypes = string | number type WantedKeys |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | the-ress |
| 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