Repository navigation
Any number can be assigned to enum member type #22311
Description
Activity
- changed the title
[-]Any number can be assigning to enum member type[/-][+]Any number can be assigned to enum member type[/+]on Mar 3, 2018 DanielRosenwasser commented
on Mar 3, 2018 MemberMore actionsI was very close to marking this as a duplicate (mostly with #6131 in mind, but also sort of #8020 - see #8020 (comment)).
The key thing here is that we're working with an individual enum member type, not just an enum type.
- addedSuggestionAn idea for TypeScriptAn idea for TypeScriptIn DiscussionNot yet reached consensusNot yet reached consensusBugA bug in TypeScriptA bug in TypeScriptand removedIn DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
on Mar 3, 2018 Yes, I expected member type is
0in this case, so I should be able to assign0but not5.- addedSuggestionAn idea for TypeScriptAn idea for TypeScriptIn DiscussionNot yet reached consensusNot yet reached consensusand removedBugA bug in TypeScriptA bug in TypeScript
on Mar 3, 2018 RyanCavanaugh commented
on Apr 16, 2018 MemberMore actionsSo we'd allow e.g.
const x: X.A = 5 + 0but not= 5?RyanCavanaugh commented
on Aug 7, 2018 MemberMore actionsThe key thing here is that we're working with an individual enum member type, not just an enum type.
The problem here is that
Xis just an alias forX.A | X.B, so any argument about assignability toX.Aapplies equally to assignability toX.Given the back compat constraints and unlikelihood of finding a bug in userland, keeping the current behavior seems like the best choice of action.
- addedDeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionand removedIn DiscussionNot yet reached consensusNot yet reached consensus
on Aug 7, 2018
Search Terms:
enum assign number
Code
Expected behavior:
2 errors: when assigning number literal and wrong enum member.
Actual behavior:
Typescript allows assigning any number to specific member type.
Playground Link:
http://bit.ly/2CZsUrK