Title: Allow narrowing generic type to single element of union type · Issue #17713 · microsoft/TypeScript · GitHub
Open Graph Title: Allow narrowing generic type to single element of union type · Issue #17713 · microsoft/TypeScript
X Title: Allow narrowing generic type to single element of union type · Issue #17713 · microsoft/TypeScript
Description: It is a fairly common pattern to create a set of generic components, and then to use the generic component type within the system. Currently, typescript has an issue handling cases where some values of a generic component depend on other...
Open Graph Description: It is a fairly common pattern to create a set of generic components, and then to use the generic component type within the system. Currently, typescript has an issue handling cases where some value...
X Description: It is a fairly common pattern to create a set of generic components, and then to use the generic component type within the system. Currently, typescript has an issue handling cases where some value...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/17713
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow narrowing generic type to single element of union type","articleBody":"It is a fairly common pattern to create a set of generic components, and then to use the generic component type within the system. Currently, typescript has an issue handling cases where some values of a generic component depend on others.\r\n\r\n**TypeScript Version:** 2.4.0 / nightly (2.5.0-dev.201xxxxx)\r\n2.4\r\n**Code**\r\n\r\n```ts\r\nlet index = {\r\n a: {\r\n arg: 'a',\r\n fn: (a: string) => {a.toUpperCase()}\r\n },\r\n b: {\r\n arg: 1,\r\n fn: (b: number) => {b + 1}\r\n }\r\n}\r\n\r\nlet runFn= \u003cK extends keyof (typeof index)>(key: K) => {\r\n let i = index[key]\r\n let arg = i.arg\r\n let fn = i.fn\r\n fn(arg) // Error: compiler doesn't understand that fn and arg will match\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nNo error, since we know that `arg` and `fn` are pulled off of the same map entry.\r\n\r\n**Actual behavior:**\r\n`Error: cannot invoke expression whose type lacks a call signature`","author":{"url":"https://github.com/dlants","@type":"Person","name":"dlants"},"datePublished":"2017-08-09T23:54:11Z","url":"https://github.com/microsoft/TypeScript/issues/17713"}
| 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:ac79bee5-b2d2-c34f-65cd-48a662940d09 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D85C:2D40DE:CE7DB:106001:6B00F6FE |
| html-safe-nonce | 9f034eb3c99aded18dc86dd535c718ec5b1914809a1c5a1a9c2ff18179d47517 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODVDOjJENDBERTpDRTdEQjoxMDYwMDE6NkIwMEY2RkUiLCJ2aXNpdG9yX2lkIjoiNTcxMDYwNzQyOTI5NzgyOTYzMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b435fe99dbd649bddd25ca2b1cceeca544ecf0e9938d2e1fc12dce174d96f912 |
| hovercard-subject-tag | issue:249194782 |
| 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/17713/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3eb659fb29cb0d786b19d9b263d15d19f6bde8683793717c744eb082f6d5b9a1/microsoft/TypeScript/issues/17713 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3eb659fb29cb0d786b19d9b263d15d19f6bde8683793717c744eb082f6d5b9a1/microsoft/TypeScript/issues/17713 |
| og:image:alt | It is a fairly common pattern to create a set of generic components, and then to use the generic component type within the system. Currently, typescript has an issue handling cases where some value... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dlants |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width