Title: Incorrect type inference of object spread, when spreaded object is referenced via interface and created by class instantiation · Issue #13409 · microsoft/TypeScript · GitHub
Open Graph Title: Incorrect type inference of object spread, when spreaded object is referenced via interface and created by class instantiation · Issue #13409 · microsoft/TypeScript
X Title: Incorrect type inference of object spread, when spreaded object is referenced via interface and created by class instantiation · Issue #13409 · microsoft/TypeScript
Description: TypeScript Version: 2.1.X (Playground) Code interface I { x: number, y: number, z: () => void } class MyClass implements I { constructor(public x: number, public y: number) { } z() { alert(this.x + this.y) } } var x: I = new MyClass(5, 7...
Open Graph Description: TypeScript Version: 2.1.X (Playground) Code interface I { x: number, y: number, z: () => void } class MyClass implements I { constructor(public x: number, public y: number) { } z() { alert(this.x +...
X Description: TypeScript Version: 2.1.X (Playground) Code interface I { x: number, y: number, z: () => void } class MyClass implements I { constructor(public x: number, public y: number) { } z() { alert(this....
Opengraph URL: https://github.com/microsoft/TypeScript/issues/13409
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect type inference of object spread, when spreaded object is referenced via interface and created by class instantiation","articleBody":"**TypeScript Version:** 2.1.X (Playground)\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface I { x: number, y: number, z: () => void }\r\n\r\nclass MyClass implements I {\r\n constructor(public x: number, public y: number) {\r\n }\r\n z() { alert(this.x + this.y) }\r\n}\r\n\r\nvar x: I = new MyClass(5, 7);\r\nvar o = { ...x }\r\nalert(o.z); // undefined\r\n```\r\n\r\n**Expected behavior:**\r\nCompile error. Either MyClass incorrectly implements `I` interface requiring to define `z` as `z=()=>alert(this.x + this.y)` or at `alert(o.z)` reporting there is no such a property on `o`, or report something similar to [FlowType](https://flowtype.org/try/#0JYOwLgpgTgZghgYwgAgJLIN7IB4C5kgCuAtgEbQA0yAnvkWZcgF74AUAlMgLwB8yAbgHtgAE2QBfAFCSEAGzgBnBcgCy1AMLylmSchy565KLpoGSRkwkEgFYKIQRhBUDjr1S9TV1jizoYVjAAC2AFADpsZABqZGDQsOpOKSlJfjgofTRuAggAd1UNLQVWAFYqAHZ2AG5U9ORBbKww5sipX39WQTCmauQAej7kQhARCBhQCBEgA).\r\n\r\n**Actual behavior:**\r\nNo compiler warnings and runtime error when trying to invoke `o.z()`.\r\n\r\n**Note:**\r\nWhen I change a definition of `I` this way: `interface I { x: number, y: number, z(): void }`, I get an error `Property 'z' does not exist on type '{ x: number; y: number; }'` as expected.","author":{"url":"https://github.com/OleksandrNechai","@type":"Person","name":"OleksandrNechai"},"datePublished":"2017-01-11T11:27:07Z","url":"https://github.com/microsoft/TypeScript/issues/13409"}
| 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:e1393978-f556-6ce6-cf83-4617b10da093 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E242:29AEE8:2C25B90:3AD86E0:6B01C9F3 |
| html-safe-nonce | 8f6c3604bf69b8910ad246f167f8e6a4c5f5724012356553c0c81313506afe0f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjQyOjI5QUVFODoyQzI1QjkwOjNBRDg2RTA6NkIwMUM5RjMiLCJ2aXNpdG9yX2lkIjoiMjA1ODE5Mjc0NTkzNDI4MzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | aa5953b1c7a2fc2f3c69fee635dbcb9c1ff18773a2dacf7c549d72108651e30a |
| hovercard-subject-tag | issue:200068604 |
| 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/13409/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1e4d0eef1dd326d381937d931c24819b0d8c1a7bcf66d38a722ee71990d2c81e/microsoft/TypeScript/issues/13409 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1e4d0eef1dd326d381937d931c24819b0d8c1a7bcf66d38a722ee71990d2c81e/microsoft/TypeScript/issues/13409 |
| og:image:alt | TypeScript Version: 2.1.X (Playground) Code interface I { x: number, y: number, z: () => void } class MyClass implements I { constructor(public x: number, public y: number) { } z() { alert(this.x +... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | OleksandrNechai |
| 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