-
Notifications
You must be signed in to change notification settings - Fork 12.8k
TypeScript integer enum objects can be assigned any integer value #38294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I understand why TS enums behave as above (They are not types). But the Typescript documentation says:
But running the following seems to contradict that.
|
yes exactly, the whole idea of using enum getting failed here. In case of string enums its not the case. const enum Mode{ which seems fair, why such enforcement is not added for integers. It supposed to be. |
Duplicate #26362 and others; please search before logging new issues when the behavior you're describing has been present since TypeScript first shipped 7 years ago. |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
I have enum as follows.
const enum Mode{
Add=1,
Edit=22
}
let currentMode:Mode=222222;
Above code is considered as valid code by compiler.
It should throw compile because it is directly assigned integer. It should enforce to assign Value as
let currentMode:Mode=Mode.Add; //Direct int should not be allowed
it should throw compile error because only allowed values should be 1 and 22.
Its Typed Script.
The text was updated successfully, but these errors were encountered: