Title: Unexpected type narrowing in finally block with return in both try and catch block · Issue #35644 · microsoft/TypeScript · GitHub
Open Graph Title: Unexpected type narrowing in finally block with return in both try and catch block · Issue #35644 · microsoft/TypeScript
X Title: Unexpected type narrowing in finally block with return in both try and catch block · Issue #35644 · microsoft/TypeScript
Description: TypeScript Version: 3.7.2 Search Terms: try catch finally return Code const main = () => { let hoge: string | undefined = undefined; try { hoge = 'hoge!'; return; // Bug disappears after removing this return. } catch { return; // Bug dis...
Open Graph Description: TypeScript Version: 3.7.2 Search Terms: try catch finally return Code const main = () => { let hoge: string | undefined = undefined; try { hoge = 'hoge!'; return; // Bug disappears after removing t...
X Description: TypeScript Version: 3.7.2 Search Terms: try catch finally return Code const main = () => { let hoge: string | undefined = undefined; try { hoge = 'hoge!'; return; // Bug disappears after...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/35644
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unexpected type narrowing in finally block with return in both try and catch block","articleBody":"**TypeScript Version:** 3.7.2\r\n\r\n**Search Terms:** try catch finally return\r\n\r\n**Code**\r\n```typescript\r\nconst main = () => {\r\n let hoge: string | undefined = undefined;\r\n try {\r\n hoge = 'hoge!';\r\n return; // Bug disappears after removing this return.\r\n } catch {\r\n return; // Bug disappears after removing this return.\r\n } finally {\r\n if (hoge) {\r\n hoge.length;\r\n }\r\n return;\r\n }\r\n}\r\n\r\nmain();\r\n```\r\n\r\n\r\n**Expected behavior:**\r\nIn `finally` block, `hoge`'s type is `string | undefined`\r\n\r\n**Actual behavior:**\r\nIn `finally` block, `hoge`'s type is only `undefined`, and `Property 'length' does not exist on type 'never'.` error occured.\r\n\r\n[Playgroung Link](https://www.typescriptlang.org/play/index.html?ssl=1&ssc=1&pln=17&pc=1#code/MYewdgzgLgBAtgQwJZhgXhgCgJToHwwDeAUDGTADYCmsAFiAOZUBcM0ATigzAD4wCuYACZUAZiipD0A4WIlCA3KXJR2ATyLLy5ek2kByXVQCE+pdu3sa-dmAUwA9A5gAhftyFIICAA4+qCOwQMAiiUFTsMFZwIABuXDBQtF5R1rYAdFowAL4wwAhQwLSaFuRWUDZ2js5uHl6+-oHBoeGR0XEJSSnllZnaueJgCBQUGiSlZEiiWEa44xPaRunUYAxJ5hPZWZZpdllbW8SIKDhKQA)\r\n\r\n\r\n**Related Issues:**\r\n- https://github.com/Microsoft/TypeScript/issues/28153\r\n- https://github.com/microsoft/TypeScript/issues/18478","author":{"url":"https://github.com/s2terminal","@type":"Person","name":"s2terminal"},"datePublished":"2019-12-12T02:50:09Z","url":"https://github.com/microsoft/TypeScript/issues/35644"}
| 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:b5e9ab7d-4495-2b9d-1a80-723365111a3c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AA8A:2C3566:CD5E4E:110E48C:6B00F50A |
| html-safe-nonce | 5d945dc480b1a871acb7b70bef01f97205c495e810f3dbd4877ccaa890044020 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQThBOjJDMzU2NjpDRDVFNEU6MTEwRTQ4Qzo2QjAwRjUwQSIsInZpc2l0b3JfaWQiOiIzNTg1MjMxMDEzMDU3NDU5NDY2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7e30794f5f63de90f9e24273f17a0d85f3f9d4c3efbba4050a6c505f9b78561f |
| hovercard-subject-tag | issue:536725672 |
| 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/35644/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3cd8ac91eb5ba565f2ac305f43314ad0b47b6c91217e38e919145eb8b2e0830c/microsoft/TypeScript/issues/35644 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3cd8ac91eb5ba565f2ac305f43314ad0b47b6c91217e38e919145eb8b2e0830c/microsoft/TypeScript/issues/35644 |
| og:image:alt | TypeScript Version: 3.7.2 Search Terms: try catch finally return Code const main = () => { let hoge: string | undefined = undefined; try { hoge = 'hoge!'; return; // Bug disappears after removing t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | s2terminal |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width