Title: Never type error in switch default · Issue #10600 · microsoft/TypeScript · GitHub
Open Graph Title: Never type error in switch default · Issue #10600 · microsoft/TypeScript
X Title: Never type error in switch default · Issue #10600 · microsoft/TypeScript
Description: TypeScript Version: 2.0.0 beta Code interface Clazz{ type: 'A' | 'B' | 'C' } let obj:Clazz = { type: 'A' }; switch(obj.type){ case 'A': console.log(obj.type); break; case 'B': console.log(obj.type); break; case 'C': console.log(obj.type)...
Open Graph Description: TypeScript Version: 2.0.0 beta Code interface Clazz{ type: 'A' | 'B' | 'C' } let obj:Clazz = { type: 'A' }; switch(obj.type){ case 'A': console.log(obj.type); break; case 'B': console.log(obj.type)...
X Description: TypeScript Version: 2.0.0 beta Code interface Clazz{ type: 'A' | 'B' | 'C' } let obj:Clazz = { type: 'A' }; switch(obj.type){ case 'A': console.log(obj.type)...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/10600
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Never type error in switch default","articleBody":"\u003c!-- BUGS: Please use this template. -->\n\n\u003c!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->\n\n\u003c!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->\n\n**TypeScript Version:** 2.0.0 beta\n\n**Code**\n\n``` ts\ninterface Clazz{\n type: 'A' | 'B' | 'C'\n}\n\nlet obj:Clazz = {\n type: 'A'\n};\n\nswitch(obj.type){\n case 'A':\n console.log(obj.type);\n break;\n case 'B':\n console.log(obj.type);\n break;\n case 'C':\n console.log(obj.type);\n break;\n default:\n console.log(obj.type);\n break;\n}\n\n```\n\n**Expected behavior:**\nCompile successful.\n\n**Actual behavior:** \nerror TS2339: Property 'type' does not exist on type 'never'.\nCan compile successfully without `default`\n\n**Suggestion:**\nWell I know never type is a good way.\nBut in this case, value may be comes from a web API response.\nSo wanna add some protection code here, but get an error.\n","author":{"url":"https://github.com/k8w","@type":"Person","name":"k8w"},"datePublished":"2016-08-30T02:22:45Z","url":"https://github.com/microsoft/TypeScript/issues/10600"}
| 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:d29ae8ac-5455-1d33-800e-2ae57b1405a6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B5D4:1AD228:111EA5:16C6C0:6B04B0F5 |
| html-safe-nonce | 762db7fced365c54065b277555983ee7ff5328bc36befafeb09e9913fd19819d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNUQ0OjFBRDIyODoxMTFFQTU6MTZDNkMwOjZCMDRCMEY1IiwidmlzaXRvcl9pZCI6IjQwODYyMzY0ODI4MjQ4NzYyNzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9129d4c23fe33029aae60b25450f3029a3f15d9086924e274c3b3b479d022da4 |
| hovercard-subject-tag | issue:173915438 |
| 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/10600/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5cb48f7c43993ba404fa62c26e3f023a9a6e5d595c5eaf26fe2a2ca685e5a481/microsoft/TypeScript/issues/10600 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5cb48f7c43993ba404fa62c26e3f023a9a6e5d595c5eaf26fe2a2ca685e5a481/microsoft/TypeScript/issues/10600 |
| og:image:alt | TypeScript Version: 2.0.0 beta Code interface Clazz{ type: 'A' | 'B' | 'C' } let obj:Clazz = { type: 'A' }; switch(obj.type){ case 'A': console.log(obj.type); break; case 'B': console.log(obj.type)... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | k8w |
| hostname | github.com |
| expected-hostname | github.com |
| None | f1d110ea058a0915c1d8aa3fc2069fa15801e128f591e5762525abe77490ecb1 |
| 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 | ffa22a65e4c46d376940fe34b05e6a7e9c7fdb9b |
| 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