Title: Value can change "during" `await`, but compiler doesn't seem to know that · Issue #46439 · microsoft/TypeScript · GitHub
Open Graph Title: Value can change "during" `await`, but compiler doesn't seem to know that · Issue #46439 · microsoft/TypeScript
X Title: Value can change "during" `await`, but compiler doesn't seem to know that · Issue #46439 · microsoft/TypeScript
Description: Bug Report I'm receiving the following error... This condition will always return 'false' since the types '"b"' and '"a"' have no overlap.(2367) ...but the value might be "a". The condition might not return false. It's worth looking at t...
Open Graph Description: Bug Report I'm receiving the following error... This condition will always return 'false' since the types '"b"' and '"a"' have no overlap.(2367) ...but the value might be "a". The condition might n...
X Description: Bug Report I'm receiving the following error... This condition will always return 'false' since the types '"b"' and '"a"' have no overlap.(2367) ...b...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/46439
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Value can change \"during\" `await`, but compiler doesn't seem to know that","articleBody":"# Bug Report\r\n\r\nI'm receiving the following error...\r\n\r\n> This condition will always return 'false' since the types '\"b\"' and '\"a\"' have no overlap.(2367)\r\n\r\n...but the value _might_ be `\"a\"`. The condition might not return `false`. It's worth looking at the code snippets below, as I think they describe the issue better.\r\n\r\n### 🔎 Search Terms\r\n\r\n- TS2367\r\n- Condition always returns false\r\n- Value changes during `await`\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nThis does not seem to be a recent regression. When I test in the playground, I see this problem in all v4 versions.\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.5.0-beta#code/DYUwLgBAzmCGYgFwQOSxRAPqgRhgvKugNwBQpsUAngHYDGEAZgK71gCWA9jRLABQBKCAG9SEcdDgIIhFHjJiJsAO6x2kAAoAnTgFt2UEADotIKJ2AA3EIIUSI7RhD4x4IGflnoho+-bAAFjrKEDQgIQCiWjpafCgBIMDAnCgCZPYAvqRZFIKkrtJeKMRAA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\nlet state: 'a' | 'b' = 'a';\r\n\r\nasync function a() {\r\n state = 'b';\r\n\r\n await Promise.resolve();\r\n\r\n // The following line has an error that I think should not happen:\r\n if (state === 'a') {\r\n throw new Error('hello');\r\n }\r\n}\r\n\r\na()\r\nstate = 'a';\r\n```\r\n\r\nHere's another example that I think better isolates the issue:\r\n\r\n```ts\r\nlet state: 'a' | 'b' = 'a';\r\n\r\nasync function a() {\r\n state = 'b';\r\n\r\n await Promise.resolve();\r\n\r\n const newState: 'a' | 'b' = state;\r\n console.log(newState); // \u003c- type seems incorrect here\r\n}\r\n\r\na()\r\nstate = 'a';\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nGot TS2367.\r\n\r\n### 🙂 Expected behavior\r\n\r\nThere is no error.","author":{"url":"https://github.com/EvanHahn","@type":"Person","name":"EvanHahn"},"datePublished":"2021-10-20T02:19:47Z","url":"https://github.com/microsoft/TypeScript/issues/46439"}
| 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:9c2795ce-360d-2841-978c-ca4cfae9ae00 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8ECA:3670FE:997186:CE7BEA:6B04DACA |
| html-safe-nonce | 8475bd325e261717679dba23deee31fe7722d588f063336d9a8b77aecdcb9654 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RUNBOjM2NzBGRTo5OTcxODY6Q0U3QkVBOjZCMDREQUNBIiwidmlzaXRvcl9pZCI6IjIwODQzNzczMTczNTgyMzAyMTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ea1695cd84aa423895acb342aa43b297a46e8fad638b7d4869448a9157ae72a2 |
| hovercard-subject-tag | issue:1030905886 |
| 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/46439/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ec0f62d2857512f78e8e27fd6921ee39128a4e5482e647a3729b9a9f47a40278/microsoft/TypeScript/issues/46439 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ec0f62d2857512f78e8e27fd6921ee39128a4e5482e647a3729b9a9f47a40278/microsoft/TypeScript/issues/46439 |
| og:image:alt | Bug Report I'm receiving the following error... This condition will always return 'false' since the types '"b"' and '"a"' have no overlap.(2367) ...but the value might be "a". The condition might n... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | EvanHahn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 194dacb8acfd3e4d3ffb2704e0b1f10327f0dad690a7142acc7b0e0a2d073965 |
| 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 | 6c35540a0a2991ee20bd053ba2601cce33f72cb1 |
| 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