René's URL Explorer Experiment


Title: Reconsider assignability of number to enum type. · Issue #26362 · microsoft/TypeScript · GitHub

Open Graph Title: Reconsider assignability of number to enum type. · Issue #26362 · microsoft/TypeScript

X Title: Reconsider assignability of number to enum type. · Issue #26362 · microsoft/TypeScript

Description: Search Terms number assignable enum Suggestion Remove assignability of number to enum types. Type number is currently assignable to numeric enum types. I am aware that this was intentionally implemented as a special case for convenience....

Open Graph Description: Search Terms number assignable enum Suggestion Remove assignability of number to enum types. Type number is currently assignable to numeric enum types. I am aware that this was intentionally implem...

X Description: Search Terms number assignable enum Suggestion Remove assignability of number to enum types. Type number is currently assignable to numeric enum types. I am aware that this was intentionally implem...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/26362

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Reconsider assignability of number to enum type.","articleBody":"## Search Terms\r\n\r\nnumber assignable enum\r\n\r\n## Suggestion\r\n\r\nRemove assignability of number to enum types.\r\n\r\nType number is currently assignable to numeric enum types. I am aware that this was intentionally implemented as a special case for convenience.\r\n\r\nWith recent improvements to generics (particularly conditional types), I believe that the convenience of number -> enum assignability may now be outweighed by the power of \"distinctness\" of NOT allowing assignability in that direction.\r\n\r\nRemoving this special case behavior would also probably have the benefit of simplifying some code in the TypeScript compiler and reducing risk of future bugs. Here's an example of a bug that was caused by the special case behavior of number->enum assignability: https://github.com/Microsoft/TypeScript/issues/10738\r\n\r\n## Use Cases\r\n\r\nIf number is NOT assignable to enum types, then it would enable the use of conditional types to distinguish numeric literal/enum types from plain old number, similar to the difference between \r\nstring literal/enum types and plain string.\r\n\r\nMy particular use case is probably too complex to try to present a full example, but here's a high level description...\r\n\r\nI am generating typescript code/interfaces from a Swagger document for making API calls. There are two parts to this:\r\n\r\n1. The compile-time static types of interfaces for the API's \"models\" (data structures). This is obviously used for static compile-time analysis to ensure that API request/response data is used properly. This includes generated enum types (both number and string) for properties that are defined as enums in the Swagger schema.\r\n2. The run-time representation of the schema for the API's \"models\". This is used to generate forms, grid column configurations, etc., at run time based on the API \"model\" schemas. At the core of this is a discriminated union of interfaces containing the pertinent schema info for all supported data types for the properties of the API's \"models\". The interface for each data type is different. For example, \"Number\" data can have min/max values, indication of whether it's integer or floating point. \"NumberEnum\" simply contains a list of valid numeric values and generated names for each value (which match the actual names of values in corresponding generated enum type from [1] above). The Swagger JSON document is parsed at run time and converted into appropriate data structures to represent the API's \"models\" in terms of these data type schema interfaces.\r\n\r\nIn order to link these two halves together and have strictly typed run-time schema utilities that make use of the compile time types of the \"model\" interfaces, part of my solution requires a helper type that maps from the type of a property in a \"model\" interface to the type of that field's schema definition interface.\r\n\r\nCurrently, I can accurately distinguish between string enum vs plain string types, but I cannot do the same for number enum vs plain number. Numeric enum properties incorrectly have their types mapped to the data schema interface type for plain numeric data.\r\n\r\n## Examples\r\n\r\nHere's an over-simplified example of the type mapping I am attempting, with comments indicating the results I would expect if number is NOT assignable to number enum:\r\n\r\n```ts\r\nenum StringEnum {\r\n    A = \"A\",\r\n    B = \"B\"\r\n}\r\n\r\nenum NumberEnum {\r\n    A,\r\n    B\r\n}\r\n\r\ntype Test\u003cT> = T extends number\r\n    ? (number extends T ? \"number\" : \"number-enum\")\r\n    : T extends string\r\n        ? (string extends T ? \"string\" : \"string-enum\")\r\n        : never;\r\n\r\nlet testString: Test\u003cstring>; // type: \"string\"\r\nlet testStringEnum: Test\u003cStringEnum>; // type: \"string-enum\"\r\nlet testNumber: Test\u003cnumber>; // type: \"number\"\r\nlet testNumberEnum: Test\u003cNumberEnum>; // type: \"number-enum\"\r\n```\r\n\r\nWith the current implementation of number->enum assignability, the type of `testNumberEnum` is `\"number\"` instead of `\"number-enum\"`.\r\n\r\nAside from that, there's all the usual benefits of the stricter typing/assignability: plain numbers will need to be explicitly cast to an enum type before assigning (forces developer to consider whether it is correct).\r\n\r\nThen there's the breaking change and inconvenience: plain numbers will need to be explicitly cast to an enum type before assigning (forces developer to consider whether it is correct).\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n* [ ] This wouldn't be a breaking change in existing TypeScript / JavaScript code\r\n* [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [x] This could be implemented without emitting different JS based on the types of the expressions\r\n* [x] This isn't a runtime feature (e.g. new expression-level syntax)\r\n\r\n","author":{"url":"https://github.com/UselessPickles","@type":"Person","name":"UselessPickles"},"datePublished":"2018-08-10T16:49:03Z","url":"https://github.com/microsoft/TypeScript/issues/26362"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:48dbdb02-b7fc-915b-d514-2fec56c63135
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id88A6:22DB35:27D5C5B:32D5ED8:6B018AF9
html-safe-nonce514254e07dfb21c07b2817e9d9af1830391c9972558000c1e4ca218fa8d5d077
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OEE2OjIyREIzNToyN0Q1QzVCOjMyRDVFRDg6NkIwMThBRjkiLCJ2aXNpdG9yX2lkIjoiNzUyMjA4NDY5NjEyNjIyOTI0MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaca5252bafa28fd511aba67ae6099418ea828d2dcef6bfd6abca4268c679f986a8
hovercard-subject-tagissue:349586035
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/26362/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f81ef1de82c175c1ad5bc1fc878dd22688ef7acdd4fc68deee145a522964442a/microsoft/TypeScript/issues/26362
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f81ef1de82c175c1ad5bc1fc878dd22688ef7acdd4fc68deee145a522964442a/microsoft/TypeScript/issues/26362
og:image:altSearch Terms number assignable enum Suggestion Remove assignability of number to enum types. Type number is currently assignable to numeric enum types. I am aware that this was intentionally implem...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameUselessPickles
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/26362#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F26362
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F26362
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/26362
Reloadhttps://github.com/microsoft/TypeScript/issues/26362
Reloadhttps://github.com/microsoft/TypeScript/issues/26362
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests312 (312)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/insights
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/26362
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/26362
Reconsider assignability of number to enum type.https://github.com/microsoft/TypeScript/issues/26362#top
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/UselessPickles
Jeff Lau (UselessPickles)https://github.com/UselessPickles
on Aug 10, 2018https://github.com/microsoft/TypeScript/issues/26362#issue-349586035
#10738https://github.com/microsoft/TypeScript/issues/10738
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
on Aug 10, 2018https://github.com/microsoft/TypeScript/issues/26362#event-1783328245
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
on Aug 10, 2018https://github.com/microsoft/TypeScript/issues/26362#event-1783330338
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Aug 10, 2018https://github.com/microsoft/TypeScript/issues/26362#issuecomment-412198483
#17734https://github.com/microsoft/TypeScript/issues/17734
#21546https://github.com/microsoft/TypeScript/issues/21546
#11559https://github.com/microsoft/TypeScript/issues/11559
#15591https://github.com/microsoft/TypeScript/issues/15591
#8020https://github.com/microsoft/TypeScript/issues/8020
#18409https://github.com/microsoft/TypeScript/issues/18409
https://github.com/DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
on Aug 10, 2018https://github.com/microsoft/TypeScript/issues/26362#issuecomment-412198938
https://github.com/UselessPickles
Jeff Lau (UselessPickles)https://github.com/UselessPickles
on Aug 11, 2018https://github.com/microsoft/TypeScript/issues/26362#issuecomment-412251931
Ryan Cavanaugh (@RyanCavanaugh)https://github.com/RyanCavanaugh
Daniel Rosenwasser (@DanielRosenwasser)https://github.com/DanielRosenwasser
https://github.com/UselessPickles
Jeff Lau (UselessPickles)https://github.com/UselessPickles
on Aug 11, 2018https://github.com/microsoft/TypeScript/issues/26362#issuecomment-412253143
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Add a Flaghttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Add%20a%20Flag%22
on Aug 13, 2018https://github.com/microsoft/TypeScript/issues/26362#event-1786236838
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Aug 13, 2018https://github.com/microsoft/TypeScript/issues/26362#issuecomment-412642086
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Aug 13, 2018https://github.com/microsoft/TypeScript/issues/26362#event-1786249492
https://github.com/UselessPickles
Jeff Lau (UselessPickles)https://github.com/UselessPickles
on Aug 13, 2018https://github.com/microsoft/TypeScript/issues/26362#issuecomment-412654808
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Aug 14, 2018https://github.com/microsoft/TypeScript/issues/26362#issuecomment-412926338
https://github.com/evmar
Evan Martin (evmar)https://github.com/evmar
on Aug 14, 2018https://github.com/microsoft/TypeScript/issues/26362#issuecomment-412930427
https://github.com/UselessPickles
Jeff Lau (UselessPickles)https://github.com/UselessPickles
on Aug 14, 2018https://github.com/microsoft/TypeScript/issues/26362#issuecomment-412962394
Ryan Cavanaugh (@RyanCavanaugh)https://github.com/RyanCavanaugh
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Aug 14, 2018https://github.com/microsoft/TypeScript/issues/26362#issuecomment-412967715
Jeff Lau (@UselessPickles)https://github.com/UselessPickles
https://github.com/UselessPickles
Jeff Lau (UselessPickles)https://github.com/UselessPickles
on Aug 14, 2018https://github.com/microsoft/TypeScript/issues/26362#issuecomment-412972738
https://github.com/UselessPickles
Jeff Lau (UselessPickles)https://github.com/UselessPickles
on Aug 24, 2018https://github.com/microsoft/TypeScript/issues/26362#issuecomment-415861539
Ryan Cavanaugh (@RyanCavanaugh)https://github.com/RyanCavanaugh
https://github.com/UselessPickles
Jeff Lau (UselessPickles)https://github.com/UselessPickles
on Aug 29, 2018https://github.com/microsoft/TypeScript/issues/26362#issuecomment-417019590
https://github.com/UselessPickles
Jeff Lau (UselessPickles)https://github.com/UselessPickles
on Mar 25, 2019https://github.com/microsoft/TypeScript/issues/26362#issuecomment-476018475
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/26362#event-20415768128
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/26362
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/26362
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.