Title: Implicit conversion of number to const enum · Issue #6131 · microsoft/TypeScript · GitHub
Open Graph Title: Implicit conversion of number to const enum · Issue #6131 · microsoft/TypeScript
X Title: Implicit conversion of number to const enum · Issue #6131 · microsoft/TypeScript
Description: The following code compiles, even though variable n obviously is assigned value that is incompatible with its type. const enum BinaryDigit { zero = 0, one = 1 } let n: BinaryDigit = 2; Is there any reason why the compiler allows an impli...
Open Graph Description: The following code compiles, even though variable n obviously is assigned value that is incompatible with its type. const enum BinaryDigit { zero = 0, one = 1 } let n: BinaryDigit = 2; Is there any...
X Description: The following code compiles, even though variable n obviously is assigned value that is incompatible with its type. const enum BinaryDigit { zero = 0, one = 1 } let n: BinaryDigit = 2; Is there any...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/6131
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Implicit conversion of number to const enum","articleBody":"The following code compiles, even though variable `n` obviously is assigned value that is incompatible with its type.\n\n``` ts\nconst enum BinaryDigit {\n zero = 0,\n one = 1\n}\n\nlet n: BinaryDigit = 2;\n```\n\nIs there any reason why the compiler allows an implicit conversion of numbers to const enums?\n\nAn instance of a base class cannot be implicitly converted to an instance of a derived class. I would have expected the same for const enums and numbers (all const enum values \"are\" numbers, but not all numbers \"are\" const enum values). If you do not consider numbers and const enum values equialent types, that would be even more reason to disallow implicit conversion.\n","author":{"url":"https://github.com/crobi","@type":"Person","name":"crobi"},"datePublished":"2015-12-17T12:41:30Z","url":"https://github.com/microsoft/TypeScript/issues/6131"}
| 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:cabeb2fa-4bed-d41f-26c7-ac86c5e5ef9a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D63E:1D92B2:DD3A1:137005:6B0463CE |
| html-safe-nonce | 905634529cfaa4974ceb751f83acd00890de1f1bf22442e7bc4f7e946a0d0467 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjNFOjFEOTJCMjpERDNBMToxMzcwMDU6NkIwNDYzQ0UiLCJ2aXNpdG9yX2lkIjoiMzg1NzIzMTUwMjM2Njc2MTkzNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | eb9beb4c01582f4b7a0d773da71a387e7d59314a05cfca19a428c397ad003b2b |
| hovercard-subject-tag | issue:122727389 |
| 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/6131/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7da751284bc5c375e43502e0a35ecc6ce7876184988977dff9bdfcbf39eac89d/microsoft/TypeScript/issues/6131 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7da751284bc5c375e43502e0a35ecc6ce7876184988977dff9bdfcbf39eac89d/microsoft/TypeScript/issues/6131 |
| og:image:alt | The following code compiles, even though variable n obviously is assigned value that is incompatible with its type. const enum BinaryDigit { zero = 0, one = 1 } let n: BinaryDigit = 2; Is there any... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | crobi |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2d58451b4bcb73c33c67bfb6b28fb75fe6d5e279daf9b560fa4fd832f3d8c9a6 |
| 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 | 03e114520787ad27289207f153520ef97461127c |
| 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