Title: Union of generic indexed types works incorrectly · Issue #26608 · microsoft/TypeScript · GitHub
Open Graph Title: Union of generic indexed types works incorrectly · Issue #26608 · microsoft/TypeScript
X Title: Union of generic indexed types works incorrectly · Issue #26608 · microsoft/TypeScript
Description: I have two generic indexed types type ExtendedService
Open Graph Description: I have two generic indexed types type ExtendedService
X Description: I have two generic indexed types type ExtendedService<T> = { [K in keyof T]: T[K] & { __$daemonMode?: string; __$action?: string; }; }; type Service<T> = { [K in keyof T]: T[K] &...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/26608
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Union of generic indexed types works incorrectly","articleBody":"I have two generic indexed types\r\n\r\n```ts\r\ntype ExtendedService\u003cT> = {\r\n [K in keyof T]: T[K] & {\r\n __$daemonMode?: string;\r\n __$action?: string;\r\n };\r\n};\r\n\r\ntype Service\u003cT> = {\r\n [K in keyof T]: T[K] & {id?: string};\r\n};\r\n```\r\n\r\nAnd use them like this\r\n\r\n```ts\r\nexport const createService = \u003cT>(\r\n ServiceCtr: ExtendedService\u003cT> & Service\u003cT>\r\n) => {\r\n ...\r\n Object.keys(ServiceCtr).forEach(key => {\r\n const method = (ServiceCtr)[key as keyof T];\r\n const {__$daemonMode, __$action, id} = method;\r\n ...\r\n }\r\n}\r\n```\r\n\r\nVS Code output for `method` type is\r\n\r\n```ts\r\nconst method: ({ [K in keyof T]: T[K] & {\r\n __$daemonMode?: string;\r\n __$action?: string;\r\n}; } & Service\u003cT>)[keyof T]\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nproperties `__$daemonMode`, `__$action`, `id` exists on `method` variable;\r\n`const {__$daemonMode, __$action, id} = method; ` has no errors;\r\n\r\n**Actual behavior:**\r\n\r\nI got an error\r\n```\r\n[ts] Type '(ExtendedService\u003cT> & Service\u003cT>)[keyof T]' has no property '__$daemonMode' and no string index signature.\r\n```\r\n`__$action` and `id` produces the same error;\r\n\r\n\r\nP.S.\r\n\r\nExpression\r\n\r\n```ts\r\nconst x: (ExtendedService\u003c{z: {}}> & Service\u003c{z: {}}>)['z'];\r\nconst {__$daemonMode, __$action, id} = x;\r\n```\r\n\r\nworks as expected","author":{"url":"https://github.com/IIIristraM","@type":"Person","name":"IIIristraM"},"datePublished":"2018-08-22T18:21:08Z","url":"https://github.com/microsoft/TypeScript/issues/26608"}
| 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:bf54e573-6a62-9668-745c-20808fa340a2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8126:4279A:22CE047:2ED6FE7:6B01A342 |
| html-safe-nonce | bd5920e9a31075f31d9744b759e50166fd42d9434c3786e10b19fd0922f14adf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTI2OjQyNzlBOjIyQ0UwNDc6MkVENkZFNzo2QjAxQTM0MiIsInZpc2l0b3JfaWQiOiIyMjU2NDE4Mjk2ODkzMTIxMzQ2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d3cdc31f75fbd44229b2de73f82f4003161d626710bd7c5d1c573aa4c4650771 |
| hovercard-subject-tag | issue:353068628 |
| 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/26608/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7d8c56a20950b2b29f25181b647045d86973dd0e690aa325a075befb0d5f11e4/microsoft/TypeScript/issues/26608 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7d8c56a20950b2b29f25181b647045d86973dd0e690aa325a075befb0d5f11e4/microsoft/TypeScript/issues/26608 |
| og:image:alt | I have two generic indexed types type ExtendedService |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | IIIristraM |
| 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