Title: Pick
Open Graph Title: Pick
X Title: Pick
Description: TypeScript Version: 3.2.1 Search Terms: 3.2.1 extends intersection generic Code type Omit
Open Graph Description: TypeScript Version: 3.2.1 Search Terms: 3.2.1 extends intersection generic Code type Omit
X Description: TypeScript Version: 3.2.1 Search Terms: 3.2.1 extends intersection generic Code type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; type Func<T> = (arg: T) =>...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/28884
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Pick\u003cT, Exclude\u003ckeyof T, K>> & Pick\u003cT, Extract\u003ckeyof T, K>> should be assignable to T","articleBody":"**TypeScript Version:** 3.2.1\r\n\r\n**Search Terms:**\r\n3.2.1\r\nextends\r\nintersection generic\r\n\r\n**Code**\r\n\r\n```ts\r\ntype Omit\u003cT, K extends keyof T> = Pick\u003cT, Exclude\u003ckeyof T, K>>;\r\n\r\ntype Func\u003cT> = (arg: T) => null\r\n\r\ntype Context = 'Context';\r\n\r\nexport function withRouteContextPropConsumer\u003c\r\n T extends { routeContext: Context }\r\n>(\r\n funcToWrap: Func\u003cT>,\r\n): Func\u003cOmit\u003cT, \"routeContext\">> {\r\n return (args: Omit\u003cT, \"routeContext\">) => {\r\n const routeContext: Context = 'Context';\r\n return funcToWrap({ ...args, routeContext });\r\n };\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nCode compiles without errors\r\n\r\n**Actual behavior:**\r\n```\r\nArgument of type '{ routeContext: \"Context\"; }' is not assignable to parameter of type 'T'.\r\n```\r\n\r\n**Playground Link:** http://www.typescriptlang.org/play/#src=type%20Omit%3CT%2C%20K%20extends%20keyof%20T%3E%20%3D%20Pick%3CT%2C%20Exclude%3Ckeyof%20T%2C%20K%3E%3E%3B%0A%0Atype%20Func%3CT%3E%20%3D%20(arg%3A%20T)%20%3D%3E%20null%0A%0Atype%20Context%20%3D%20'Context'%3B%0A%0Aexport%20function%20withRouteContextPropConsumer%3C%0A%20%20%20%20T%20extends%20%7B%20routeContext%3A%20Context%20%7D%0A%3E(%0A%20%20%20%20funcToWrap%3A%20Func%3CT%3E%2C%0A)%3A%20Func%3COmit%3CT%2C%20%22routeContext%22%3E%3E%20%7B%0A%20%20%20%20return%20(args%3A%20Omit%3CT%2C%20%22routeContext%22%3E)%20%3D%3E%20%7B%0A%20%20%20%20%20%20%20%20const%20routeContext%3A%20Context%20%3D%20'Context'%3B%0A%20%20%20%20%20%20%20%20return%20funcToWrap(%7B%20...args%2C%20routeContext%20%7D)%3B%0A%20%20%20%20%7D%3B%0A%7D\r\n**Related Issues:** Nothing obvious\r\n\r\nAfter upgrading from 3.0.3 to 3.2.1, it seems that tsc has (at least partially) lost the ability to reason about constrained generics.\r\n\r\nIn the example above (one of our React context helper functions, modified to remove the React dependency), the function is parameterised over a constrained generic:\r\n```ts\r\nT extends { routeContext: Context }\r\n```\r\n\r\nBut a few lines later, the compiler complains that the generic `T` may not have a `routeContext` attribute. T *must* have a `routeContext` attribute however, because of the constraint. Perhaps the `Omit` helper is confusing things?","author":{"url":"https://github.com/djrodgerspryor","@type":"Person","name":"djrodgerspryor"},"datePublished":"2018-12-06T23:10:29Z","url":"https://github.com/microsoft/TypeScript/issues/28884"}
| 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:26fef5d7-e8e9-694a-6135-c49f03bfe2f1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A4FA:19AA62:297323F:34A59AB:6B01A2A8 |
| html-safe-nonce | e868d4f7a5991d35aedbabbc8b1627320a69576079836b9bfb8d0e74edc5ae8d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNEZBOjE5QUE2MjoyOTczMjNGOjM0QTU5QUI6NkIwMUEyQTgiLCJ2aXNpdG9yX2lkIjoiNzEwMDc2NjcxMjgxMTc3MjU2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4907aa725b7d3a7974e616ee752dfda1c24da65452f20e3a92bc20bb3bd60238 |
| hovercard-subject-tag | issue:388437262 |
| 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/28884/issue_layout |
| twitter:image | https://opengraph.githubassets.com/04bdf3804f1481e51974e0bd83e5dbf14addf7d407dbe94f6181d5c61c2dec52/microsoft/TypeScript/issues/28884 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/04bdf3804f1481e51974e0bd83e5dbf14addf7d407dbe94f6181d5c61c2dec52/microsoft/TypeScript/issues/28884 |
| og:image:alt | TypeScript Version: 3.2.1 Search Terms: 3.2.1 extends intersection generic Code type Omit |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | djrodgerspryor |
| 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