-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
request: optionally disable enum/number implicit conversion #17734
Comments
This breaks flag enums, where bit operations are allowed. |
actually, you could still allow we already have a way of representing collections of constant integers in the language (ie. classes with |
if we were to do it allover again, i would have flags and enums be separate entities. but that is not possible now. any changes to the enums now would lead to a massive breaking change. The TS code base for instance relies on flags extensively, and i am sure we are not unique in this regard. |
yeah, like i said. can we have an option to do this? |
we have a limited budget of options, each option adds maintenance costs on the team and learning cost on users. |
well, if what you want is a collection of integer values, then the language already has a non-type-safe alternative: classes. eg:
this performs almost as well as an as far as i know, since the beginning, Anders has always sold typescript on the grounds that it's a typesafe javascript, useful for building large projects with large teams. adding type safety to enums would certainly fit this goal. i'm pretty sure it would help fix more bugs than would simply providing some syntactic sugar for collections of consts. |
on a related note, i just discovered that you can't have an
results in so which is it? is |
see #2049 |
hah, so i wrote a tslint rule to do this, and after running on the tsc project i see now why you wouldn't want to do this. here's my favorite:
that's an enumeration of all the values that a variable of type why not just this? :
same for |
this one specifically is wrong, but the general rule stands. look at things like NodeFlags. |
absolutely. and nowhere[*] is a variable of type [*] except for a few times where it's compared to indeed, here's a complete diff of changes that would satisfy this: tsc.patch.txt (also, this: |
I would also like the ability to check for this. I defined enums entirely so that I could use static typechecking to make sure that they were being used correctly; right now, typescript isn't capturing that. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
now that we have union types, can we please have an option to disable the enum/number implicit casts?
I'd really like the following to give me an error:
The text was updated successfully, but these errors were encountered: