Title: Some information is lost when working with keyof against type arguments · Issue #48989 · microsoft/TypeScript · GitHub
Open Graph Title: Some information is lost when working with keyof against type arguments · Issue #48989 · microsoft/TypeScript
X Title: Some information is lost when working with keyof against type arguments · Issue #48989 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms Hard topic to search for IMO, but I tried phrases like typescript generic interface lose type information and I only found similar issues but not related. 🕗 Version & Regression Information I was having trouble ...
Open Graph Description: Bug Report 🔎 Search Terms Hard topic to search for IMO, but I tried phrases like typescript generic interface lose type information and I only found similar issues but not related. 🕗 Version & Regr...
X Description: Bug Report 🔎 Search Terms Hard topic to search for IMO, but I tried phrases like typescript generic interface lose type information and I only found similar issues but not related. 🕗 Version & ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/48989
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Some information is lost when working with keyof against type arguments","articleBody":"# Bug Report\r\n\r\n### 🔎 Search Terms\r\n\r\nHard topic to search for IMO, but I tried phrases like `typescript generic interface lose type information` and I only found similar issues but not related.\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nI was having trouble using version 4.5.5 (that we're currently using), but I could also reproduce it in the latest version available in the playground (4.6.2). I checked versions back to 3.3.3 in the playground and they all reported the same issue.\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.6.2#code/PTAECEFEHEEkDlQDEBKBBAspA6geRQNKgDKAKgKpJIBQ1ALgJ4AOApqLgEYBWLAxnQRYMAPLgA0oUgD5QAXlABvANpEAlgDtQAayEB7AGbsAugC52Ko6BYAPOi3UATAM6TQAflBEz6lgDcWAE4Avko6DAbsoABkoE50ARoA5kYA3LQadgH6AIa8bBgMsOqZOXmK1KCVoAC2DMTxSQBq2QA2AK4sZnEJ6olpVTWFxSyJgc3tnaDqbdUcgWlBtNkc3bl0oLwt2U4uaCvxa+DbLKIyChVVvLrq3W38ugEAFEwJvtl2oAEs2Q7XLQygXTcPh0My4ACUikWF0qTDaHBaql4oFGdHGHWE0ke+lULBaDng2Wqk04PH4ghE4kkUkh5wGAy+dDaAU0dAAFqonAA6IFkuhKHF4glElipGGgRbQkCgSDwAAiyHQWDwhBIFCotGlUDgiFgGAACgAZSBYeCkNCkWC4RBkSg0aibbYuAqkZhsVTVJgtFjE4rOoYlXJsOlVWr1HqJdFseQAIhj-VDAZGY1aHTkoAAtABGBa0R07UAFIqBvIACV0+MCWeEsCstnszkLSayQZkNjsjl2+wCh2OwiLwxbeTO4quN3idzoD0evJBZlgtPFAycbVYT1n-HBCfpoHZnK5qKjwmms0CUkeMdqxeTASjMa34slDq2BYHJZY5crAQATDW6x3GzfQJShYNt607UA9lWfgjicE5YBHAYx1ue512Bfh50XHdKhXNcZ3QugH2w3cOW5Q9UxOE85gCc9LyTUZbwo+9twlagpTAWUFT1I0TVlc1LWtNU7Tza44lANkKwcKt0x8AB3JtryHD9JKrfsGFdVhzzkpsNJYR5wQfZD1jeCYs3TCSvyzA8WDRCjjxmajaKvYYGLvB8HVE9YLKkn8ZJYeSgKUz8fOrF03S0-ydLdfTDM80ATI6b9zJUn9rNsiZ7NPGiL2cuxXKYrcgA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\n// BEGIN FRAMEWORK STUFF\r\n\r\ntype ObjectKey\u003cO, T> = {[K in keyof O]: O[K] extends T ? K : never}[keyof O & string];\r\n\r\ninterface MyInterface {\r\n myStringValue: string;\r\n myIntegerValue: number;\r\n}\r\n\r\nabstract class AbstractBase\u003cO> {\r\n constructor(private readonly object: O) {}\r\n\r\n public getValue\u003cT>(fieldName: ObjectKey\u003cO, T>) {\r\n return this.object[fieldName];\r\n }\r\n}\r\n\r\n// END FRAMEWORK STUFF\r\n\r\n// BEGIN IMPLEMENTATION STUFF\r\n\r\nclass MyType implements MyInterface {\r\n myStringValue = \"\";\r\n myIntegerValue = -1;\r\n}\r\n\r\nclass MyInterfaceHolder1\u003cI extends MyInterface> extends AbstractBase\u003cMyInterface> {\r\n constructor(object: I) {\r\n super(object);\r\n this.getValue\u003cnumber>(\"myIntegerValue\");\r\n }\r\n}\r\nclass MyInterfaceHolder2\u003cI extends MyInterface> extends AbstractBase\u003cI> {\r\n constructor(object: I) {\r\n super(object);\r\n this.getValue\u003cnumber>(\"myIntegerValue\"); // Argument of type 'string' is not assignable to parameter of type 'ObjectKey\u003cI, number>'.(2345)\r\n }\r\n}\r\n\r\n// END IMPLEMENTATION STUFF\r\n\r\nconst holder1 = new MyInterfaceHolder1\u003cMyType>(new MyType());\r\nconst value1 = holder1.getValue\u003cnumber>(\"myIntegerValue\");\r\n\r\nconst holder2 = new MyInterfaceHolder1\u003cMyType>(new MyType());\r\nconst value2 = holder2.getValue\u003cnumber>(\"myIntegerValue\");\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nI lose some type information within the super-class when working with a generic argument.\r\n\r\n### 🙂 Expected behavior\r\n\r\nI feel like it **should** be able to maintain type information here.","author":{"url":"https://github.com/anton-johansson","@type":"Person","name":"anton-johansson"},"datePublished":"2022-05-06T11:25:24Z","url":"https://github.com/microsoft/TypeScript/issues/48989"}
| 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:9c16d984-5cdc-4e81-c26c-c93936bf13d1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B9B6:7A60E:2EA6DEE:3BD4EFB:6B01BCB4 |
| html-safe-nonce | 192d1eaf61242bc53766122ab46433547f173ee624aac32b8ef35b61c6c5f9c4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOUI2OjdBNjBFOjJFQTZERUU6M0JENEVGQjo2QjAxQkNCNCIsInZpc2l0b3JfaWQiOiI4MzI0Nzc1OTAxNDg5MzgwNTMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 76c9c69c7d285b42bf630e3480e0bf296be730e54f4d21b2b3a4e2856153b7dd |
| hovercard-subject-tag | issue:1227741317 |
| 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/48989/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6c3650524ecde3d5f0fc6e37b859e774cef39680f366008908d7c680f8f366c0/microsoft/TypeScript/issues/48989 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6c3650524ecde3d5f0fc6e37b859e774cef39680f366008908d7c680f8f366c0/microsoft/TypeScript/issues/48989 |
| og:image:alt | Bug Report 🔎 Search Terms Hard topic to search for IMO, but I tried phrases like typescript generic interface lose type information and I only found similar issues but not related. 🕗 Version & Regr... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | anton-johansson |
| 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