Title: Discriminated union intersected with discriminant does not join to the original type when discriminated · Issue #36333 · microsoft/TypeScript · GitHub
Open Graph Title: Discriminated union intersected with discriminant does not join to the original type when discriminated · Issue #36333 · microsoft/TypeScript
X Title: Discriminated union intersected with discriminant does not join to the original type when discriminated · Issue #36333 · microsoft/TypeScript
Description: TypeScript Version: master Search Terms: Discriminated union intersection narrowing Code type A = { key: "one", value: number } | { key: "two", value: string }; type A_one = A & { key: "one" }; function foo(a1: A_one): number { if (a1.ke...
Open Graph Description: TypeScript Version: master Search Terms: Discriminated union intersection narrowing Code type A = { key: "one", value: number } | { key: "two", value: string }; type A_one = A & { key: "one" }; fun...
X Description: TypeScript Version: master Search Terms: Discriminated union intersection narrowing Code type A = { key: "one", value: number } | { key: "two", value: string }; type A_one = A &...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/36333
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Discriminated union intersected with discriminant does not join to the original type when discriminated","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\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 FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!--\r\nPlease try to reproduce the issue with the latest published version. It may have already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n-->\r\n**TypeScript Version:** master\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\nDiscriminated union intersection narrowing\r\n\r\n**Code**\r\n\r\n```ts\r\ntype A = { key: \"one\", value: number } | { key: \"two\", value: string };\r\n\r\ntype A_one = A & { key: \"one\" };\r\n\r\nfunction foo(a1: A_one): number {\r\n if (a1.key) {\r\n\r\n }\r\n return a1.value; // no error\r\n}\r\n\r\nfunction bar(a1: A_one): number {\r\n return a1.value; // error\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nConsistent behavior between `foo` and `bar`, though I'm not sure how easy that is.\r\n- Making them both error feels like a regression.\r\n- Making them both ok would need to introduce some new logic for arbitrary property access.\r\n\r\n\r\n\r\n\r\n**Actual behavior:**\r\nThe control flow through the joint point is doing some type reduction not present in the plain version.\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior -->\r\n\r\n[link](http://www.typescriptlang.org/play/?ts=3.8.0-dev.20200119&ssl=1&ssc=1&pln=14&pc=2#code/C4TwDgpgBAglC8UDeUDWEQC4oCID2AdhDgDRQBuAhgDYCuE2BtAtgEYQBOUAvlAD7I0GbDmAB3PKQo162AM7AOASwIBzHgG4AUFtCRYAfULREcAGSD0WXMZyadAM1oEAxsCWEoDvHgAUlAEZsGCMiAEpGFnYuJC0oeKglByh-AIA6KzDkHQSeOISOCGBaDgIoQLSqOggNeIB6OqgCPChODjwOLW5HZzcPMtZKDlTg0IgIpqjObNzC4tLy9Kr6WqgG1o52zu4gA)\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n\r\nFound when looking at #36323.\r\n\r\nThis was (probably) introduced by the fix at #35513.\r\n","author":{"url":"https://github.com/jack-williams","@type":"Person","name":"jack-williams"},"datePublished":"2020-01-21T17:55:13Z","url":"https://github.com/microsoft/TypeScript/issues/36333"}
| 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:56904130-8dab-233f-3933-74e8e0e66c4f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 91D4:177808:4509B2:5CE384:6B04A133 |
| html-safe-nonce | ee306f1cb5100153cc4ca30847716590f6cf7f88306aab1f2e8487a8353d8579 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MUQ0OjE3NzgwODo0NTA5QjI6NUNFMzg0OjZCMDRBMTMzIiwidmlzaXRvcl9pZCI6Ijc5MjczMTU2NDY0ODMwNDY3MDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 833cfb78db6938b594ed29cd106d67121e05c76d48e3be56f642a1fcc2ab324f |
| hovercard-subject-tag | issue:553036466 |
| 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/36333/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3273573a9106125156444903ca510a090d8d2dde039f44ef1c77cf0fb3e285d9/microsoft/TypeScript/issues/36333 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3273573a9106125156444903ca510a090d8d2dde039f44ef1c77cf0fb3e285d9/microsoft/TypeScript/issues/36333 |
| og:image:alt | TypeScript Version: master Search Terms: Discriminated union intersection narrowing Code type A = { key: "one", value: number } | { key: "two", value: string }; type A_one = A & { key: "one" }; fun... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jack-williams |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9784b6f42e2d5eac4e394fa88cad134c0dc5b6662b4ff2787a1ed1ef5a96331d |
| 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 | 3fd14143b75b2af7b76bbd23b069867d091adfcc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width