Title: Mapped Types with Intersections in React Props Definition, results in type is not assignable error · Issue #27201 · microsoft/TypeScript · GitHub
Open Graph Title: Mapped Types with Intersections in React Props Definition, results in type is not assignable error · Issue #27201 · microsoft/TypeScript
X Title: Mapped Types with Intersections in React Props Definition, results in type is not assignable error · Issue #27201 · microsoft/TypeScript
Description: Search Terms: Mapped Types with React Props incorrect assignable reference Code the intent is for this to be a decorator type Mutate
Open Graph Description: Search Terms: Mapped Types with React Props incorrect assignable reference Code the intent is for this to be a decorator type Mutate
X Description: Search Terms: Mapped Types with React Props incorrect assignable reference Code the intent is for this to be a decorator type Mutate<T extends string | number | symbol> = Readonly< { [K in...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/27201
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mapped Types with Intersections in React Props Definition, results in type is not assignable error","articleBody":"**Search Terms:**\r\nMapped Types with React Props\r\nincorrect assignable reference\r\n**Code**\r\nthe intent is for this to be a decorator\r\n```ts \r\ntype Mutate\u003cT extends string | number | symbol> = Readonly\u003c\r\n { [K in T]: MutationFn }\r\n>\r\nconst withMutation = \u003c\r\n Key extends string,\r\n V extends OperationVariables,\r\n TData extends object = any\r\n>(\r\n mutationProps: Omit\u003cMutationProps\u003cTData, V>, 'children'>\r\n) => {\r\n return \u003cP extends object>(\r\n Component: ComponentType\u003c\r\n P &\r\n Mutate\u003cKey> &\r\n Pick\u003cMutationResult\u003cTData>, 'loading' | 'data' | 'error'>\r\n >\r\n ) =>\r\n class WithMutation extends React.Component\u003cP> {\r\n render() {\r\n const key = (mutationProps.mutation\r\n .definitions[0] as OperationDefinitionNode).name!.value as K\r\n return (\r\n \u003cMutation {...mutationProps}>\r\n {(mutateFn: MutationFn, result: MutationResult\u003cTData>) => {\r\n const error = result.error! \r\n\r\n return (\r\n \u003cComponent\r\n loading={result.loading!}\r\n error={error}\r\n {...result.data}\r\n {...this.props}\r\n {...{ [key]: mutateFn }}\r\n />\r\n )\r\n }}\r\n \u003c/Mutation>\r\n )\r\n }\r\n }\r\n}\r\n\r\n// A *self-contained* demonstration of the problem follows...\r\n// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.\r\n```\r\n\r\n\r\n**Expected behavior:**\r\nthe props should be correct, for reference the mapped type behavior produces this I think\r\n```ts\r\ntype Mutate\u003cT extends string | number | symbol> = Readonly\u003c\r\n { [K in T]: MutationFn }\r\n>\r\n\r\nMutate\u003c'submitForm'> === Readonly\u003c{ submitForm: MutationFn }>\r\n```\r\n\r\nnot actually sure why it's saying the type is not assignable since \r\ntype '((IntrinsicAttributes & IntrinsicClassAttributes\u003cComponent\u003cP & Readonly\u003c{ [K in Key]: MutationFn\u003cany, OperationVariables>; }> & Pick\u003cMutationResult\u003cTData>, \"data\" | \"loading\" | \"error\">, any, any>> & Readonly\u003c...> & Readonly\u003c...>) | (IntrinsicAttributes & ... 2 more ... & { ...; }))[\"loading\"]'\r\n\r\nshould evaluate to boolean.\r\n**Actual behavior:**\r\n\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior -->\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n","author":{"url":"https://github.com/IllusionElements","@type":"Person","name":"IllusionElements"},"datePublished":"2018-09-18T21:51:58Z","url":"https://github.com/microsoft/TypeScript/issues/27201"}
| 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:93c9ce5b-b8da-87be-efdb-3737c4709ab7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8990:317608:331E586:40BFB3D:6B01D153 |
| html-safe-nonce | a6f86d38b0bb1247166988b4c55be96447be4fde63a7b03cef120ec4301b667d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OTkwOjMxNzYwODozMzFFNTg2OjQwQkZCM0Q6NkIwMUQxNTMiLCJ2aXNpdG9yX2lkIjoiMzA4OTY0MzIwMjE1MjYxNjI3NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 88410a1bdba3633b928f831ae4136924d50b51aab451fd263b9d4c09871d49c8 |
| hovercard-subject-tag | issue:361498277 |
| 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/27201/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7be5c0f43a9903cc86bbe2ee343b4aedf5949b5c4b66b0a2b7ae4b55b03fd62c/microsoft/TypeScript/issues/27201 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7be5c0f43a9903cc86bbe2ee343b4aedf5949b5c4b66b0a2b7ae4b55b03fd62c/microsoft/TypeScript/issues/27201 |
| og:image:alt | Search Terms: Mapped Types with React Props incorrect assignable reference Code the intent is for this to be a decorator type Mutate |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | IllusionElements |
| 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