Title: Polymorphic this type does not work with conditional mapped types · Issue #32550 · microsoft/TypeScript · GitHub
Open Graph Title: Polymorphic this type does not work with conditional mapped types · Issue #32550 · microsoft/TypeScript
X Title: Polymorphic this type does not work with conditional mapped types · Issue #32550 · microsoft/TypeScript
Description: TypeScript Version: 3.5.3 Search Terms: Polymorphic this mapped conditional Code type NumberedKeys
Open Graph Description: TypeScript Version: 3.5.3 Search Terms: Polymorphic this mapped conditional Code type NumberedKeys
X Description: TypeScript Version: 3.5.3 Search Terms: Polymorphic this mapped conditional Code type NumberedKeys<T> = { [K in keyof T]: T[K] extends number ? K : never }[keyof T]; type X = NumberedKeys<...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/32550
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Polymorphic this type does not work with conditional mapped types","articleBody":"**TypeScript Version:** 3.5.3\r\n\r\n**Search Terms:** Polymorphic this mapped conditional\r\n\r\n**Code**\r\n\r\n```ts\r\ntype NumberedKeys\u003cT> = { [K in keyof T]:\r\n T[K] extends number ? K : never }[keyof T];\r\n\r\ntype X = NumberedKeys\u003cExample>;\r\n\r\nclass Example {\r\n public a: number;\r\n public b: string;\r\n public c: number;\r\n\r\n public constructor() {\r\n this.a = 3;\r\n this.b = \"hello\";\r\n this.c = 42;\r\n }\r\n\r\n public getNumber(key: NumberedKeys\u003cthis>): number {\r\n return this[key];\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior:** `NumberedKeys\u003cExample>` works fine, but `NumberedKeys\u003cthis>` does not.\r\n\r\n**Actual behavior:** \r\n```\r\nType 'this[{ [K in keyof this]: this[K] extends number ? K : never; }[keyof this]]' is not assignable to type 'number'.\r\n Type 'this[this[keyof this] extends number ? keyof this : never]' is not assignable to type 'number'.\r\n Type 'this[keyof this]' is not assignable to type 'number'.\r\n Type 'this[string] | this[number] | this[symbol]' is not assignable to type 'number'.\r\n Type 'this[string]' is not assignable to type 'number'.\r\n```\r\n\r\n**Playground Link:** [link](https://www.typescriptlang.org/play/#code/C4TwDgpgBAcgrgWwEYQE4QCYGkIgM4A8AKgHxQC8UA3lANpZQCWAdlANa4D2AZlEQLoAuAFBQxfevygQAHsAjMMeKM0QpUUAPxQGglRABuaKAF9aHEDz78A3MOGhIUABoVYatJhz4CAURkAhghgADYQJHbCAMYhAXjK-kGh0FSi4mBwSCGMUVABeqrIaHbiUBlZOVBIenjAqCwA5iXpmdm5UQUeqJGl5W1QUZzMtahwUcCcqAAUAJTUaaViwAAWjHgAdAFuAMzNi1Ara+tIbgBEyxAhIZyne4uHG7mUACwATHcm9r2tlQ0QwPAitMLHpAeovLhCA8SDNOkD5vsxOhgHBUKwHuZcLYFqZhJ8gA)\r\n\r\n**Related Issues:** n/a\r\n","author":{"url":"https://github.com/mcsrobert","@type":"Person","name":"mcsrobert"},"datePublished":"2019-07-25T11:50:33Z","url":"https://github.com/microsoft/TypeScript/issues/32550"}
| 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:8517179e-435f-e9a2-7cb7-342a51c92627 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DA60:2D40DE:21E7F2A:2B2AE56:6B01B821 |
| html-safe-nonce | 6b3834e39bdf4a1c66aaa1c51ccc38502e4a42e6ee993ac636796135b24ab539 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTYwOjJENDBERToyMUU3RjJBOjJCMkFFNTY6NkIwMUI4MjEiLCJ2aXNpdG9yX2lkIjoiNjgxNDk4NDk1MDA3NzU2OTA1NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1cc78ab27d0501a491e1ddcc69ac37a0cc41b168db07a151f60da804360271ea |
| hovercard-subject-tag | issue:472821509 |
| 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/32550/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fb587c21dd4322d1bfc18f01eb89a93972af19ef1e05d4fdb9bad861df753a70/microsoft/TypeScript/issues/32550 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fb587c21dd4322d1bfc18f01eb89a93972af19ef1e05d4fdb9bad861df753a70/microsoft/TypeScript/issues/32550 |
| og:image:alt | TypeScript Version: 3.5.3 Search Terms: Polymorphic this mapped conditional Code type NumberedKeys |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mcsrobert |
| 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