Title: Discriminated union types better error reporting · Issue #10867 · microsoft/TypeScript · GitHub
Open Graph Title: Discriminated union types better error reporting · Issue #10867 · microsoft/TypeScript
X Title: Discriminated union types better error reporting · Issue #10867 · microsoft/TypeScript
Description: This the example from docs: interface Square { kind: "square"; size: number; } interface Rectangle { kind: "rectangle"; width: number; height: number; } interface Circle { kind: "circle"; radius: number; } type Shape = Square | Rectangle...
Open Graph Description: This the example from docs: interface Square { kind: "square"; size: number; } interface Rectangle { kind: "rectangle"; width: number; height: number; } interface Circle { kind: "circle"; radius: n...
X Description: This the example from docs: interface Square { kind: "square"; size: number; } interface Rectangle { kind: "rectangle"; width: number; height: number; } interface Circle { kind:...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/10867
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Discriminated union types better error reporting","articleBody":"This the example from docs:\n\n\n``` ts\ninterface Square {\n kind: \"square\";\n size: number;\n}\n\ninterface Rectangle {\n kind: \"rectangle\";\n width: number;\n height: number;\n}\n\ninterface Circle {\n kind: \"circle\";\n radius: number;\n}\n\ntype Shape = Square | Rectangle | Circle;\n\nlet shape: Shape = {\n kind: \"square\",\n width: 10,\n height: 10\n}\n```\n\nSo we create object with type `Shape` of kind `square` and try to pass incorrect other props (for this kind), and TS emits the error that object is no assignable to last type that is in union (`Circle` in this case). I believe it would be better if TS would recoginze that we are trying to make `Square` type in this case and emitted corresponding error message.\n","author":{"url":"https://github.com/wclr","@type":"Person","name":"wclr"},"datePublished":"2016-09-12T17:01:53Z","url":"https://github.com/microsoft/TypeScript/issues/10867"}
| 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:f9c94b83-cf54-b3eb-5af4-06da855a0503 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D9A6:14F601:A33116:D31FD7:6B00E176 |
| html-safe-nonce | 8c07d4f882643e3c53e34f8476eefa8302b309d03f34ccc7d041460bd697d31a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOUE2OjE0RjYwMTpBMzMxMTY6RDMxRkQ3OjZCMDBFMTc2IiwidmlzaXRvcl9pZCI6IjM4MTcxMjg2NTM5ODk0MDUwNDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 95bc16a4eee7485e0366668221e0493dd01afbc7f31afd559f0aa79e1b828e79 |
| hovercard-subject-tag | issue:176428780 |
| 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/10867/issue_layout |
| twitter:image | https://opengraph.githubassets.com/75db15e2bf6952e7006cd3aaaf04a549417b1f2d371ebe0c940d70b6a3d0a298/microsoft/TypeScript/issues/10867 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/75db15e2bf6952e7006cd3aaaf04a549417b1f2d371ebe0c940d70b6a3d0a298/microsoft/TypeScript/issues/10867 |
| og:image:alt | This the example from docs: interface Square { kind: "square"; size: number; } interface Rectangle { kind: "rectangle"; width: number; height: number; } interface Circle { kind: "circle"; radius: n... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | wclr |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width