Title: Can't use keyof index for indexing intersection of Partial
Open Graph Title: Can't use keyof index for indexing intersection of Partial
X Title: Can't use keyof index for indexing intersection of Partial
Description: Bug I'm trying to use an object's key to index an intersection into a partial of an object and another object, but I'm getting an error. Note: this error only shows up in a generic class. Using plain types I was not able to replicate it....
Open Graph Description: Bug I'm trying to use an object's key to index an intersection into a partial of an object and another object, but I'm getting an error. Note: this error only shows up in a generic class. Using pla...
X Description: Bug I'm trying to use an object's key to index an intersection into a partial of an object and another object, but I'm getting an error. Note: this error only shows up in a generic clas...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/22286
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Can't use keyof index for indexing intersection of Partial\u003cT> and another type in generic class\u003cT>.","articleBody":"**Bug**\r\nI'm trying to use an object's key to index an intersection into a partial of an object and another object, but I'm getting an error. \r\nNote: this error only shows up in a generic class. Using plain types I was not able to replicate it.\r\n\r\n**TypeScript Version:**\r\n2.7.1-insiders.20180127 (playground)\r\n2.3.1 (visual studio tools)\r\n2.7.2 (command line)\r\n\r\n**Search Terms:** \r\nKeyof, intersection, union, Partial, index, merge.\r\n\r\n**Code**\r\n\r\n``` Typescript\r\n interface Rum {\r\n \"ho hum\": string; \r\n }\r\n\r\n interface Color {\r\n \"blue\": number;\r\n }\r\n\r\n class Thingy\u003cT> {\r\n mything: Rum & Partial\u003cT>;\r\n log(param: keyof T) {\r\n console.log(this.mything[param]); //ERROR!\r\n }\r\n }\r\n```\r\n\r\n**Expected behavior:**\r\nNo errors.\r\n\r\n**Actual behavior:**\r\ntest.ts(13,25): error TS2536: Type 'keyof T' cannot be used to index type 'Rum & Partial\u003cT>'.\r\n\r\n[**Playground link**](https://www.typescriptlang.org/play/#src=%0D%0A%0D%0A%20%20%20%20interface%20Rum%20%7B%0D%0A%20%20%20%20%20%20%20%20%22ho%20hum%22%3A%20string%3B%20%0D%0A%20%20%20%20%7D%0D%0A%0D%0A%20%20%20%20interface%20Color%20%7B%0D%0A%20%20%20%20%20%20%20%20%22blue%22%3A%20number%3B%0D%0A%20%20%20%20%7D%0D%0A%0D%0A%20%20%20%20class%20Thingy%3CT%3E%20%7B%0D%0A%20%20%20%20%20%20%20%20mything%3A%20Rum%20%26%20Partial%3CT%3E%0D%0A%20%20%20%20%20%20%20%20log(param%3A%20keyof%20T)%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20console.log(this.mything%5Bparam%5D)%3B%0D%0A%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20)\r\n\r\n","author":{"url":"https://github.com/Griffork","@type":"Person","name":"Griffork"},"datePublished":"2018-03-02T07:28:48Z","url":"https://github.com/microsoft/TypeScript/issues/22286"}
| 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:d1200062-7a99-1248-2c3d-e0a296c00a96 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E8C:11EACE:2D12FC4:3C3B6E4:6B01D0C4 |
| html-safe-nonce | 6950640e550fc96df42bdeaa3a37e9d116d951e335e31eeba7c54533871d00f3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RThDOjExRUFDRToyRDEyRkM0OjNDM0I2RTQ6NkIwMUQwQzQiLCJ2aXNpdG9yX2lkIjoiNTMyODk1NDA3MTI3OTg0OTY2OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 126a297cf1a59a178a3773e8f1a9de2ddbcf64dfdfaeeed983fb1a7c0f8a4960 |
| hovercard-subject-tag | issue:301676775 |
| 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/22286/issue_layout |
| twitter:image | https://opengraph.githubassets.com/685459129335453506b8e40d88b5ce182465e75f27c60a7f683dbfbfa273faf1/microsoft/TypeScript/issues/22286 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/685459129335453506b8e40d88b5ce182465e75f27c60a7f683dbfbfa273faf1/microsoft/TypeScript/issues/22286 |
| og:image:alt | Bug I'm trying to use an object's key to index an intersection into a partial of an object and another object, but I'm getting an error. Note: this error only shows up in a generic class. Using pla... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Griffork |
| 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