Title: Incorrect hover shown for union variable in `while` loop following an exhaustive `switch` · Issue #47538 · microsoft/TypeScript · GitHub
Open Graph Title: Incorrect hover shown for union variable in `while` loop following an exhaustive `switch` · Issue #47538 · microsoft/TypeScript
X Title: Incorrect hover shown for union variable in `while` loop following an exhaustive `switch` · Issue #47538 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms while switch union narrowing never 🕗 Version & Regression Information Version: 4.5.4 This is the behavior in every version I tried, and I reviewed the FAQ for entries about while, loop, switch ⏯ Playground Link ...
Open Graph Description: Bug Report 🔎 Search Terms while switch union narrowing never 🕗 Version & Regression Information Version: 4.5.4 This is the behavior in every version I tried, and I reviewed the FAQ for entries abou...
X Description: Bug Report 🔎 Search Terms while switch union narrowing never 🕗 Version & Regression Information Version: 4.5.4 This is the behavior in every version I tried, and I reviewed the FAQ for entries ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/47538
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect hover shown for union variable in `while` loop following an exhaustive `switch`","articleBody":"# Bug Report\r\n\r\n\u003c!--\r\n Please fill in each section completely. Thank you!\r\n-->\r\n\r\n### 🔎 Search Terms\r\n\r\n\u003c!--\r\n What search terms did you use when trying to find an existing bug report?\r\n List them here so people in the future can find this one more easily.\r\n-->\r\nwhile switch union narrowing never\r\n\r\n### 🕗 Version & Regression Information\r\nVersion: 4.5.4\r\n- This is the behavior in every version I tried, and I reviewed the FAQ for entries about while, loop, switch\r\n\r\n### ⏯ Playground Link\r\n\r\n\u003c!--\r\n A link to a TypeScript Playground \"Share\" link which shows this behavior\r\n\r\n The TypeScript Workbench can be used for more complex setups, try\r\n https://www.typescriptlang.org/dev/bug-workbench/\r\n\r\n As a last resort, you can link to a repo, but these will be slower for us to investigate.\r\n-->\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=3.9.7#code/DYUwLgBAZg9jBcEBEBDNSIB9kCM8YF5k0UkBuAKAoHcALAS1AgAowAnAVxAEoIBvChCEQAztXpgAxrRawYvAcKURJKESGLp4g5boCMAaj1kIAelMoAdgE9RYFGBABbEJbA7dSnGxAoA1pSeKmoaSHg4SNpBSobGZhY2dg7Oru7Rwt6+AR4QAL5USvRQsnAQBOWapAo5SpIwliIwoAB0wDAA5sxIAGKl9CIQJEjcgZ5yZbj4o0K5ECDA6hBFJTBlFWH4CvEiKNYD4-0QliAAbiBsNcJ1DU0grR1dvauH4cPTyteNLW2dSAAycAADksBgATeogN6XISZfzvfK5IA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\nlet foo: \"aaa\" | \"bbb\" = \"aaa\";\r\n\r\nwhile (true) {\r\n switch (foo) {\r\n case \"aaa\":\r\n 1+1; //any statement\r\n break;\r\n case \"bbb\":\r\n 1+1; //any statement\r\n break;\r\n }\r\n\r\n if (foo === \"aaa\") {\r\n console.log(\"Foo is aaa\");\r\n foo = \"bbb\";\r\n } else if (foo === \"bbb\") { //says foo is never\r\n console.log(\"Foo is bbb\");\r\n console.log(\"Loop is done\");\r\n break;\r\n }\r\n}\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\n\u003c!-- What happened, and why it was wrong -->\r\nOn the line `} else if (foo === \"bbb\") {` when you hover over `foo` typescript thinks the type is never. If that was the case then you'd expect nothing inside that block to run.\r\n\r\n### 🙂 Expected behavior\r\n\r\n\u003c!-- What you expected to happen instead, and why -->\r\n`foo` should be type `\"bbb\"` here, and if you remove the switch statement it is. Furthermore if you run the compiled JS, it does hit all the console.log lines and produces\r\n```\r\nFoo is aaa\r\nFoo is bbb\r\nLoop is done\r\n```","author":{"url":"https://github.com/greg-hornby-roam","@type":"Person","name":"greg-hornby-roam"},"datePublished":"2022-01-21T02:40:19Z","url":"https://github.com/microsoft/TypeScript/issues/47538"}
| 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:f957b662-9400-b195-c592-0f485b26fbd9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C5F4:2E3FEE:28D1528:33AB68C:6B019C3A |
| html-safe-nonce | 4d0363599d4ce8c273585284bf202676ed3d6724e65075c7656b9afe0199a4ba |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNUY0OjJFM0ZFRToyOEQxNTI4OjMzQUI2OEM6NkIwMTlDM0EiLCJ2aXNpdG9yX2lkIjoiNDQxMzUxODYzODY2MTg2ODYwMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5f1617e0d18aa6d34b61d9638cf5d76ad4efd221abc280f6abd0609dab8b0a8d |
| hovercard-subject-tag | issue:1109987474 |
| 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/47538/issue_layout |
| twitter:image | https://opengraph.githubassets.com/afa44be9d1defe16312ce2f933f57e99e46ddcb1a81aedc4f8f6580b6c3f060f/microsoft/TypeScript/issues/47538 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/afa44be9d1defe16312ce2f933f57e99e46ddcb1a81aedc4f8f6580b6c3f060f/microsoft/TypeScript/issues/47538 |
| og:image:alt | Bug Report 🔎 Search Terms while switch union narrowing never 🕗 Version & Regression Information Version: 4.5.4 This is the behavior in every version I tried, and I reviewed the FAQ for entries abou... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | greg-hornby-roam |
| 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