Title: Control flow analysis should "work" in unreachable code · Issue #26914 · microsoft/TypeScript · GitHub
Open Graph Title: Control flow analysis should "work" in unreachable code · Issue #26914 · microsoft/TypeScript
X Title: Control flow analysis should "work" in unreachable code · Issue #26914 · microsoft/TypeScript
Description: TypeScript Version: master Search Terms: unreachable throw return narrowing Code function fn() { // TODO: Finish writing this function! return; const h = Math.random() > 0.5 ? 'h' : undefined; if (h) { // Error, wat const a: string = h; ...
Open Graph Description: TypeScript Version: master Search Terms: unreachable throw return narrowing Code function fn() { // TODO: Finish writing this function! return; const h = Math.random() > 0.5 ? 'h' : undefined; if (...
X Description: TypeScript Version: master Search Terms: unreachable throw return narrowing Code function fn() { // TODO: Finish writing this function! return; const h = Math.random() > 0.5 ? 'h' : unde...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/26914
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Control flow analysis should \"work\" in unreachable code","articleBody":"**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:** unreachable throw return narrowing\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction fn() {\r\n // TODO: Finish writing this function!\r\n return;\r\n\r\n const h = Math.random() > 0.5 ? 'h' : undefined;\r\n\r\n if (h) {\r\n // Error, wat\r\n const a: string = h;\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior:** No error\r\n\r\n**Actual behavior:** Error - h is possibly undefined\r\n\r\nWe get \"bug\" reports like this every once in a while, and it's hard to understand why the narrowing just stops working because the code isn't reachable. This also makes it difficult to insert debugging throws/returns earlier in the function.\r\n\r\ne.g. https://twitter.com/aendrew/status/1037301561062514688\r\n\r\n**Playground Link:** http://www.typescriptlang.org/play/#src=function%20fn()%20%7B%0A%20%20%20%20%2F%2F%20Not%20done%20yet%0A%20%20%20%20return%3B%0A%0A%20%20%20%20const%20h%20%3D%20Math.random()%20%3E%200.5%20%3F%20'h'%20%3A%20undefined%3B%0A%20%20%20%20const%20d%20%3D%20(arg%3A%20string)%20%3D%3E%20arg%3B%0A%0A%20%20%20%20if%20(h)%20%7B%0A%20%20%20%20%20%20%20%20const%20a%20%3D%20d(h)%3B%0A%20%20%20%20%7D%0A%7D%0A\r\n\r\n**Related Issues:** Believe there's one out there somewhere\r\n","author":{"url":"https://github.com/RyanCavanaugh","@type":"Person","name":"RyanCavanaugh"},"datePublished":"2018-09-05T18:15:43Z","url":"https://github.com/microsoft/TypeScript/issues/26914"}
| 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:4345fc3a-97cf-978f-30cd-0b6a514597c8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C690:345F7:85023:AC386:6B04E895 |
| html-safe-nonce | 82dde562812af1b9c4e77911c5e330a565d377082dcc56005fd3e18e7c5d66c7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNjkwOjM0NUY3Ojg1MDIzOkFDMzg2OjZCMDRFODk1IiwidmlzaXRvcl9pZCI6IjY4MjQ5MTAzMjc0NDEwNTc5NDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 22d217d9ee8ee8c6f78e5ac21cba3d5a81dbe6b284312dc036d039a58094cf75 |
| hovercard-subject-tag | issue:357345727 |
| 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/26914/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9681765d1431fb441d46a310fe97d9a86ca3854ba07f83b6cd70f4411f8fb201/microsoft/TypeScript/issues/26914 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9681765d1431fb441d46a310fe97d9a86ca3854ba07f83b6cd70f4411f8fb201/microsoft/TypeScript/issues/26914 |
| og:image:alt | TypeScript Version: master Search Terms: unreachable throw return narrowing Code function fn() { // TODO: Finish writing this function! return; const h = Math.random() > 0.5 ? 'h' : undefined; if (... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RyanCavanaugh |
| hostname | github.com |
| expected-hostname | github.com |
| None | f3851aad500d8e8dce736722ddc6fa9596e17d9fce3c53581eba968664c0bc32 |
| 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 | e29c922455fd8137f27e1cfcdf6a1e8b920b1926 |
| 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