Title: Spread and Generic · Issue #24060 · microsoft/TypeScript · GitHub
Open Graph Title: Spread and Generic · Issue #24060 · microsoft/TypeScript
X Title: Spread and Generic · Issue #24060 · microsoft/TypeScript
Description: Search Terms spread, generic, intersection Suggestion Spread operator does not work with 2.9.0-dev20180503 for generic but there is workaround by using Object.assign. Both should work. Currently, the spread syntax returns "Spread types m...
Open Graph Description: Search Terms spread, generic, intersection Suggestion Spread operator does not work with 2.9.0-dev20180503 for generic but there is workaround by using Object.assign. Both should work. Currently, t...
X Description: Search Terms spread, generic, intersection Suggestion Spread operator does not work with 2.9.0-dev20180503 for generic but there is workaround by using Object.assign. Both should work. Currently, t...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/24060
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Spread and Generic","articleBody":"## Search Terms\r\n\r\nspread, generic, intersection\r\n\r\n## Suggestion\r\n\r\nSpread operator does not work with 2.9.0-dev20180503 for generic but there is workaround by using Object.assign. Both should work. Currently, the spread syntax returns \"Spread types may only be created from object types.\"\r\n\r\nRelated to [this issue #13557 ](https://github.com/Microsoft/TypeScript/issues/13557)\r\n\r\n## Use Cases\r\n\r\nYou want to merge two objects, one (or more) is generic.\r\n\r\n## Examples\r\n\r\n```\r\n interface WithId {\r\n id: number;\r\n }\r\n interface User {\r\n name: string;\r\n }\r\n interface Developer extends User {\r\n favoriteLanguage: string;\r\n }\r\n function identifyUser\u003cT extends User>(user: T): T & WithId {\r\n const newUser = Object.assign({}, user, { id: 1 });\r\n return newUser;\r\n }\r\n function identifyUser2\u003cT extends User>(user: T): T & WithId {\r\n const newUser = {\r\n ...user, // This is not compiling\r\n id: 1\r\n };\r\n return newUser;\r\n }\r\n``` \r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n [x] This wouldn't be a breaking change in existing TypeScript / JavaScript code\r\n [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n [x] This could be implemented without emitting different JS based on the types of the expressions\r\n [x] This isn't a runtime feature (e.g. new expression-level syntax)\r\n\r\n","author":{"url":"https://github.com/MrDesjardins","@type":"Person","name":"MrDesjardins"},"datePublished":"2018-05-11T14:26:37Z","url":"https://github.com/microsoft/TypeScript/issues/24060"}
| 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:02f769ae-de45-3bfd-a3be-862090e25225 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CA24:3CBB3E:2444AC7:2E4AB0C:6B01CB31 |
| html-safe-nonce | 93115c14a326034136b7df43973a5e5ab5420557fed1caa67e6f1541ed9324b2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTI0OjNDQkIzRToyNDQ0QUM3OjJFNEFCMEM6NkIwMUNCMzEiLCJ2aXNpdG9yX2lkIjoiNTEwMTMwMjQ4ODE5NTM1ODUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7ee967723a47c9166542eea0bad49fdc678fb6700af16fcd9f76efce627ff955 |
| hovercard-subject-tag | issue:322316813 |
| 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/24060/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2da2aadc5c867632c4e9a153df240452a2978f1da48e855264e680272fad6c82/microsoft/TypeScript/issues/24060 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2da2aadc5c867632c4e9a153df240452a2978f1da48e855264e680272fad6c82/microsoft/TypeScript/issues/24060 |
| og:image:alt | Search Terms spread, generic, intersection Suggestion Spread operator does not work with 2.9.0-dev20180503 for generic but there is workaround by using Object.assign. Both should work. Currently, t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | MrDesjardins |
| 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