Title: String literal type comparison should result in an error if the compared value is invalid · Issue #7112 · microsoft/TypeScript · GitHub
Open Graph Title: String literal type comparison should result in an error if the compared value is invalid · Issue #7112 · microsoft/TypeScript
X Title: String literal type comparison should result in an error if the compared value is invalid · Issue #7112 · microsoft/TypeScript
Description: Hi, We have been adding compile time safety to the magic string problem through the excellent string literal type introduced in 1.8. One case that we are finding slipping through the safety net is the following: type Foo = 'a' | 'b'; con...
Open Graph Description: Hi, We have been adding compile time safety to the magic string problem through the excellent string literal type introduced in 1.8. One case that we are finding slipping through the safety net is ...
X Description: Hi, We have been adding compile time safety to the magic string problem through the excellent string literal type introduced in 1.8. One case that we are finding slipping through the safety net is ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/7112
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"String literal type comparison should result in an error if the compared value is invalid","articleBody":"Hi,\n\nWe have been adding compile time safety to the magic string problem through the excellent string literal type introduced in 1.8.\n\nOne case that we are finding slipping through the safety net is the following:\n\n``` typescript\ntype Foo = 'a' | 'b';\n\nconst foo: Foo = 'a';\n\nif (foo === 'bar') {\n}\n```\n\nHere the `Foo` type is being compared to an incompatible value 'bar'.\n\nIt would be nice to get an error here similar to an enum comparison error:\n\n``` typescript\nenum Foo { a, b }\nenum Bar { a, b }\nlet foo: Foo;\n\nif (foo === Bar.a) { // Operator '===' cannot be applied to types 'Foo' and 'Bar'\n}\n\n```\n\nThis is especially useful for obtaining a compile time error when the original strings `('a' | 'b')` are refactored during the course of development.\n\nI'm aware that there are workarounds involving pseudo string enums, but this is a suggestion for this primitive case.\n\nThanks.\n","author":{"url":"https://github.com/NoelAbrahams","@type":"Person","name":"NoelAbrahams"},"datePublished":"2016-02-17T13:32:46Z","url":"https://github.com/microsoft/TypeScript/issues/7112"}
| 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:b1c5a083-7e09-5654-d537-0c4d733e5f4c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8CFA:2FC714:468F6:5FBD7:6AFBF4FF |
| html-safe-nonce | 41fe4cc59567e1756736672ec9022a41f97bff001ac464ebb56d2591c5e17fdb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Q0ZBOjJGQzcxNDo0NjhGNjo1RkJENzo2QUZCRjRGRiIsInZpc2l0b3JfaWQiOiI0MTYzNjU1OTMxMjE0NDI3MzkxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4084cdf05e7782099d49840aa76ac1dc450863500d1f11c900cfa8b945d57aa0 |
| hovercard-subject-tag | issue:134280749 |
| 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/7112/issue_layout |
| twitter:image | https://opengraph.githubassets.com/55049a9d6362fd01a63c6252951f51cd548e96f38eff5f707d7bcde00d672fb1/microsoft/TypeScript/issues/7112 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/55049a9d6362fd01a63c6252951f51cd548e96f38eff5f707d7bcde00d672fb1/microsoft/TypeScript/issues/7112 |
| og:image:alt | Hi, We have been adding compile time safety to the magic string problem through the excellent string literal type introduced in 1.8. One case that we are finding slipping through the safety net is ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | NoelAbrahams |
| hostname | github.com |
| expected-hostname | github.com |
| None | fa74413a1d84dac536fcca0740780bcbd3207bafec0e51873b73ff8e8cca032f |
| 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 | b3b5633a74535d9c23385512d534c66c8fde1907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width