Title: No error on object literal containing property of wrong type for union · Issue #22129 · microsoft/TypeScript · GitHub
Open Graph Title: No error on object literal containing property of wrong type for union · Issue #22129 · microsoft/TypeScript
X Title: No error on object literal containing property of wrong type for union · Issue #22129 · microsoft/TypeScript
Description: TypeScript Version: 2.6.2, 2.7.2, 2.8.0-dev.20180222 Search Terms: Code export interface A { x?: string; } export interface B extends A { y?: number; } export interface C extends A { z?: boolean; } const passes: B | C = { x: 'hello', z: ...
Open Graph Description: TypeScript Version: 2.6.2, 2.7.2, 2.8.0-dev.20180222 Search Terms: Code export interface A { x?: string; } export interface B extends A { y?: number; } export interface C extends A { z?: boolean; }...
X Description: TypeScript Version: 2.6.2, 2.7.2, 2.8.0-dev.20180222 Search Terms: Code export interface A { x?: string; } export interface B extends A { y?: number; } export interface C extends A { z?: boolean; }...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/22129
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"No error on object literal containing property of wrong type for union","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨 -->\r\n\u003c!--\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker.\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the CONTRIBUTING guidelines: https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n-->\r\n\r\n\u003c!-- If you have a QUESTION:\r\n THIS IS NOT A FORUM FOR QUESTIONS.\r\n Ask questions at http://stackoverflow.com/questions/tagged/typescript\r\n or https://gitter.im/Microsoft/TypeScript\r\n-->\r\n\r\n\u003c!-- If you have a SUGGESTION:\r\n Most suggestion reports are duplicates, please search extra hard before logging a new suggestion.\r\n See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md\r\n-->\r\n\r\n\u003c!-- If you have a BUG:\r\n Please fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 2.6.2, 2.7.2, 2.8.0-dev.20180222\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** \r\n\r\n**Code**\r\n\r\n```ts\r\nexport interface A {\r\n x?: string;\r\n}\r\nexport interface B extends A {\r\n y?: number;\r\n}\r\nexport interface C extends A {\r\n z?: boolean;\r\n}\r\n\r\nconst passes: B | C = { x: 'hello', z: 42 };\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nI would expect to get this type of error:\r\n\r\n```\r\nTypes of property 'z' are incompatible.\r\n Type 'number' is not assignable to type 'boolean | undefined'.\r\n```\r\n\r\n**Actual behavior:**\r\n\r\nNo error. I would guess that the object literal is being inferred as a `B` with an extraneous `z` property instead of a `C`, however I would expect the rule about object literals not containing extraneous properties to apply. And what's odder is that if `x` isn't specified it _does_ give the expected error:\r\n\r\n```ts\r\nconst fails: B | C = { z: 42 };\r\n```\r\n\r\n[**Playground Link**](http://www.typescriptlang.org/play/#src=export%20interface%20A%20%7B%0D%0A%20%20x%3F%3A%20string%3B%0D%0A%7D%0D%0Aexport%20interface%20B%20extends%20A%20%7B%0D%0A%20%20y%3F%3A%20number%3B%0D%0A%7D%0D%0Aexport%20interface%20C%20extends%20A%20%7B%0D%0A%20%20z%3F%3A%20boolean%3B%0D%0A%7D%0D%0A%0D%0Aconst%20passes%3A%20B%20%7C%20C%20%3D%20%7B%20x%3A%20'hello'%2C%20z%3A%2042%20%7D%3B%0D%0A%0D%0Aconst%20fails%3A%20B%20%7C%20C%20%3D%20%7B%20z%3A%2042%20%7D%3B%0D%0A)\r\n\r\n","author":{"url":"https://github.com/pelotom","@type":"Person","name":"pelotom"},"datePublished":"2018-02-22T22:36:52Z","url":"https://github.com/microsoft/TypeScript/issues/22129"}
| 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:672dd440-bed5-4ebb-b7e3-33a59ca2a422 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C67C:1D86C4:31F985B:3F8D953:6B01D133 |
| html-safe-nonce | c5c1ce47248fb562ec1dc17e8a1e19bd9a368441e72f889621a57904997bcf9e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNjdDOjFEODZDNDozMUY5ODVCOjNGOEQ5NTM6NkIwMUQxMzMiLCJ2aXNpdG9yX2lkIjoiOTMwNzE3NTkzNzcyMzQ3Njk5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7bc6ff230b1a0cdeaa2ff56212694850eff719d2c6087973bdc45c94fea37ee3 |
| hovercard-subject-tag | issue:299534139 |
| 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/22129/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1eb9b81068220610c0a7a665ac3381d424eb94e069d5afa2ae5899bfb7551a20/microsoft/TypeScript/issues/22129 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1eb9b81068220610c0a7a665ac3381d424eb94e069d5afa2ae5899bfb7551a20/microsoft/TypeScript/issues/22129 |
| og:image:alt | TypeScript Version: 2.6.2, 2.7.2, 2.8.0-dev.20180222 Search Terms: Code export interface A { x?: string; } export interface B extends A { y?: number; } export interface C extends A { z?: boolean; }... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pelotom |
| 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