Title: Regression in 3.6: Combination of union and intersection types with literal types not resolving specific types properly · Issue #33448 · microsoft/TypeScript · GitHub
Open Graph Title: Regression in 3.6: Combination of union and intersection types with literal types not resolving specific types properly · Issue #33448 · microsoft/TypeScript
X Title: Regression in 3.6: Combination of union and intersection types with literal types not resolving specific types properly · Issue #33448 · microsoft/TypeScript
Description: TypeScript Version: 3.6.2 and 3.6.3 Search Terms: union types, intersection types, literal types Code type a = { type: 'a', data: string } type b = { type: 'b', name: string } type c = { type: 'c', other: string } type abc = a | b | c; f...
Open Graph Description: TypeScript Version: 3.6.2 and 3.6.3 Search Terms: union types, intersection types, literal types Code type a = { type: 'a', data: string } type b = { type: 'b', name: string } type c = { type: 'c',...
X Description: TypeScript Version: 3.6.2 and 3.6.3 Search Terms: union types, intersection types, literal types Code type a = { type: 'a', data: string } type b = { type: 'b', name: string } type ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/33448
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Regression in 3.6: Combination of union and intersection types with literal types not resolving specific types properly","articleBody":"\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. (done) -->\r\n**TypeScript Version:** `3.6.2` and `3.6.3`\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** union types, intersection types, literal types\r\n\r\n**Code**\r\n\r\n```ts\r\ntype a = {\r\n type: 'a',\r\n data: string\r\n}\r\ntype b = {\r\n type: 'b',\r\n name: string\r\n}\r\ntype c = {\r\n type: 'c',\r\n other: string\r\n}\r\ntype abc = a | b | c;\r\nfunction f(problem: abc & (b | c)) {\r\n if (problem.type === 'b') {\r\n console.log(problem.name);\r\n } else {\r\n console.log(problem.other);\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nTypeScript not to complain about the typings.\r\n\r\n**Actual behavior:**\r\nIn the `f` function, TypeScript says that `problem` may not have `name` because type `Property 'name' does not exist on type 'a & c'`, but `a` and `c` are mutually exclusive types and therefore not possible. It also complains that `problem` may not have `other` because `Property 'other' does not exist on type 'a & b'`, but due to the if/else, it's not possible for `problem` to be of type `b`, and in fact the only possible type for it is `c`.\r\n\r\n**Playground Link:** Since the playground is still on 3.5.1, this issue is not reproducible there. Here's a link to the example I posted above in the playground (though it is passing): https://www.typescriptlang.org/play/#code/C4TwDgpgBAhlC8UDeAoK6qkgLigchjwBo0MATGYGXAZ2ACcBLAOwHMUBfFLaAIwWSl0PXHl7EhUZjAC2EWgxbsuPKAGMBqDJnDz8aidoD2wABYR6Cpm07ddsXhsRwAPlH5u1AbhQAzAK7MasCMRsxQvgAUYPRGvAA2EDK4MI5QAGRQkR7qAJS5gtqMvlkxcYkyAHSq8LX44gVa2hhqYTRGiZXxRqzRsQlJldJyuT7aHFAQ8TTQTc3qbR0QXT195YMm5vSjklxcQA\r\n\r\n**Related Issues:** https://github.com/microsoft/TypeScript/issues/33101 looked like it *might* be related, can't quite tell.\r\n","author":{"url":"https://github.com/ReinAkane","@type":"Person","name":"ReinAkane"},"datePublished":"2019-09-16T14:38:06Z","url":"https://github.com/microsoft/TypeScript/issues/33448"}
| 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:19f3e472-55bc-d93e-5592-4a0d97b874af |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B04E:2BA76E:580022:7ABB53:6B0481D2 |
| html-safe-nonce | dae24ddbf9a1d1ae934e4380b7ec60d4c52246280fc5be6e22855586e0742909 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDRFOjJCQTc2RTo1ODAwMjI6N0FCQjUzOjZCMDQ4MUQyIiwidmlzaXRvcl9pZCI6IjE4MDk0ODYxODE5MTQ5MzU3NjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d30c57eff7b0810f7dfab744f084803af7865fe7f0d91d35642f8d3a7cc52a1d |
| hovercard-subject-tag | issue:494092562 |
| 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/33448/issue_layout |
| twitter:image | https://opengraph.githubassets.com/42a2ca6ddb419f6d168a8579e14d3a7a380800235233921b9e2cafe2dfd8bed9/microsoft/TypeScript/issues/33448 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/42a2ca6ddb419f6d168a8579e14d3a7a380800235233921b9e2cafe2dfd8bed9/microsoft/TypeScript/issues/33448 |
| og:image:alt | TypeScript Version: 3.6.2 and 3.6.3 Search Terms: union types, intersection types, literal types Code type a = { type: 'a', data: string } type b = { type: 'b', name: string } type c = { type: 'c',... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ReinAkane |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0366ddfb372682a32e92a5d86155cb08fa83e5bbe79953a968789f2f7e24c511 |
| 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 | ed3f2e01f6b7672780c586c8af0e72726374d7b6 |
| 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