Title: Object Properties Spread with Generic Object Types not allowed · Issue #15792 · microsoft/TypeScript · GitHub
Open Graph Title: Object Properties Spread with Generic Object Types not allowed · Issue #15792 · microsoft/TypeScript
X Title: Object Properties Spread with Generic Object Types not allowed · Issue #15792 · microsoft/TypeScript
Description: TypeScript Version: 2.3.2 Code Playground Example class Foo
{ setProperties(props: P) { const newProps = { ...props }; } } class Bar
{ setProperties(props: P) { const newProps = { ...props }; } } class Baz
Open Graph Description: TypeScript Version: 2.3.2 Code Playground Example class Foo
{ setProperties(props: P) { const newProps = { ...props }; } } class Bar
{ setProperties(props: P) { const newProps ...
X Description: TypeScript Version: 2.3.2 Code Playground Example class Foo<P> { setProperties(props: P) { const newProps = { ...props }; } } class Bar<P extends object> { setProperties(props: P) { con...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/15792
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Object Properties Spread with Generic Object Types not allowed","articleBody":"**TypeScript Version:** 2.3.2\r\n\r\n**Code**\r\n\r\n[Playground Example](http://www.typescriptlang.org/play/#src=class%20Foo%3CP%3E%20%7B%0A%20%20setProperties(props%3A%20P)%20%7B%0A%20%20%20%20const%20newProps%20%3D%20%7B%20...props%20%7D%3B%0A%20%20%7D%0A%7D%0A%0Aclass%20Bar%3CP%20extends%20object%3E%20%7B%0A%20%20setProperties(props%3A%20P)%20%7B%0A%20%20%20%20const%20newProps%20%3D%20%7B%20...props%20%7D%3B%0A%20%20%7D%0A%7D%0A%0Aclass%20Baz%3CP%20extends%20%7B%20%5Bprop%3A%20string%5D%3A%20any%3B%20%7D%3E%20%7B%0A%20%20setProperties(props%3A%20P)%20%7B%0A%20%20%20%20const%20newProps%20%3D%20%7B%20...props%20%7D%3B%0A%20%20%7D%0A%7D%0A%0Aclass%20Qat%3CP%20extends%20object%20%3D%20object%3E%20%7B%0A%20%20setProperties(props%3A%20P)%20%7B%0A%20%20%20%20const%20newProps%20%3D%20%7B%20...props%20%7D%3B%0A%20%20%7D%0A%7D)\r\n\r\n```ts\r\nclass Foo\u003cP> {\r\n setProperties(props: P) {\r\n const newProps = { ...props };\r\n }\r\n}\r\n\r\nclass Bar\u003cP extends object> {\r\n setProperties(props: P) {\r\n const newProps = { ...props };\r\n }\r\n}\r\n\r\nclass Baz\u003cP extends { [prop: string]: any; }> {\r\n setProperties(props: P) {\r\n const newProps = { ...props };\r\n }\r\n}\r\n\r\nclass Qat\u003cP extends object = object> {\r\n setProperties(props: P) {\r\n const newProps = { ...props };\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nThat properties are spread on class `Bar`, class `Baz`, and class `Qat`.\r\n\r\n**Actual behavior:**\r\n\r\nAll three cases report that `Spread types may only be created from object types.` In all cases, the generic could be inferred to be of an object type, so the restriction seems to be arbitrary.","author":{"url":"https://github.com/kitsonk","@type":"Person","name":"kitsonk"},"datePublished":"2017-05-12T07:49:53Z","url":"https://github.com/microsoft/TypeScript/issues/15792"}
| 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:b59dfec3-4f80-0d17-611f-494b8647603f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB22:2270F4:2E5BF16:3D8C26C:6B01D456 |
| html-safe-nonce | d5926830871b047b4e70bfcff89cbeb726d222c60a9b666582e5fd988733e12e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjIyOjIyNzBGNDoyRTVCRjE2OjNEOEMyNkM6NkIwMUQ0NTYiLCJ2aXNpdG9yX2lkIjoiNTk1OTQ0MDAzMTc4ODY4NDM3NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | deed19a27a35a31962b841a0896746926429322d2218758e9f14668bb00eb90c |
| hovercard-subject-tag | issue:228213932 |
| 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/15792/issue_layout |
| twitter:image | https://opengraph.githubassets.com/961f2615343e5b1f4b2165c15fdde5421249726e8261857a8eda473657fb47a8/microsoft/TypeScript/issues/15792 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/961f2615343e5b1f4b2165c15fdde5421249726e8261857a8eda473657fb47a8/microsoft/TypeScript/issues/15792 |
| og:image:alt | TypeScript Version: 2.3.2 Code Playground Example class Foo { setProperties(props: P) { const newProps = { ...props }; } } class Bar { setProperties(props: P) { const newProps ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kitsonk |
| 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