Title: `never` incorrectly inferred with type guard · Issue #10934 · microsoft/TypeScript · GitHub
Open Graph Title: `never` incorrectly inferred with type guard · Issue #10934 · microsoft/TypeScript
X Title: `never` incorrectly inferred with type guard · Issue #10934 · microsoft/TypeScript
Description: I was refactoring some code and suddenly some type guards in my code begin causing type errors. I've reduced my problem to the small example below. I just did npm install -g typescript@next to check that this also happens with the latest...
Open Graph Description: I was refactoring some code and suddenly some type guards in my code begin causing type errors. I've reduced my problem to the small example below. I just did npm install -g typescript@next to chec...
X Description: I was refactoring some code and suddenly some type guards in my code begin causing type errors. I've reduced my problem to the small example below. I just did npm install -g typescript@next to ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/10934
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`never` incorrectly inferred with type guard","articleBody":"I was refactoring some code and suddenly some type guards in my code begin causing type errors. I've reduced my problem to the small example below. I just did `npm install -g typescript@next` to check that this also happens with the latest version.\n\nAfter some confusion and debugging it appears that the bug happens because the class `Empty` has no methods. If I add a random dummy method to `Empty` the code compiles again.\n\n**TypeScript Version:** 2.1.0-dev.20160915\n\n**Code**\n\n``` ts\nexport type FingerTree\u003cA> = Empty | Single\u003cA>;\n\nexport class Empty {\n constructor() {};\n}\n\nexport class Single\u003cA> {\n constructor(\n public nested: boolean\n ) {};\n}\n\nexport function test(t: FingerTree\u003cany>): boolean {\n if (t instanceof Empty) {\n return true;\n } else {\n return t.nested;\n }\n}\n```\n\n**Expected behavior:**\nCode compiles without errors and `t` has the type `Singe\u003cany>` in the `else` clause in `test`.\n\n**Actual behavior:** \n`t` has the type `never` in the else clause and I get` the compile error:\n\n```\ntest.ts(17,14): error TS2339: Property 'nested' does not exist on type 'never'.\n```\n","author":{"url":"https://github.com/paldepind","@type":"Person","name":"paldepind"},"datePublished":"2016-09-15T09:26:16Z","url":"https://github.com/microsoft/TypeScript/issues/10934"}
| 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:ba9725b1-056b-990c-2933-a07b3e8d9698 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AF5E:842EC:B5A6C5:F39E90:6B00F57B |
| html-safe-nonce | d40a4425ea62e927dcce5f0392c016cafe2cea2ec6c40a2ebe2ad522f2e600ed |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRjVFOjg0MkVDOkI1QTZDNTpGMzlFOTA6NkIwMEY1N0IiLCJ2aXNpdG9yX2lkIjoiNzY0OTY5MTMzMTI5MTMxMzUzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3c1f913aa9d85432ed4be9bf99498fc8f0b14b176d1dfe355202ef2e3d92991b |
| hovercard-subject-tag | issue:177129153 |
| 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/10934/issue_layout |
| twitter:image | https://opengraph.githubassets.com/77381590db4c0a5532f84fadaacc09ec59f4c9ab45fe19743e03d00166e7c753/microsoft/TypeScript/issues/10934 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/77381590db4c0a5532f84fadaacc09ec59f4c9ab45fe19743e03d00166e7c753/microsoft/TypeScript/issues/10934 |
| og:image:alt | I was refactoring some code and suddenly some type guards in my code begin causing type errors. I've reduced my problem to the small example below. I just did npm install -g typescript@next to chec... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | paldepind |
| 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