-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Flow Enums: Syntax #7837
Comments
Please no, enums aren't standard js. Adding |
To be clear, this would be an optional, opt-in feature, we would not change the default of not requiring any transformations other than stripping types. |
@gkz this would still be added to babel and reserve |
I think flow can grab this idea for enums. https://docs.python.org/3/library/enum.html
|
I'm generally against this proposal.
I do understand that runtime features can improve dev experience, but please don't think about that in isolation. Think about where Flow is, about other tools which work together with it, about community, etc. Currently, such an approach for runtime will make things worse, not better. People in 3rd party tools won't add such feature and people will either drop these tools (with loss of DX) or will move to TS. Any of these ways won't make them happy about it. |
Sounds like the TC39 proposal should come first, then. @PinkaminaDianePie makes some good points. If Flow is still intended not to require any transpilation other than stripping annotations, then there ought to be e.g. a Babel plugin that will do the required transpilation for the TC39 proposal. If it is instead built into Flow itself, what happens to this feature if the TC39 proposal goes nowhere? Will Facebook's Flow team release a codemod to change all the code that used this feature back into standard JS+Flow? I think the issue here is that there hasn't been much context provided. The proposal seems fairly technical, jumping into the AST terms that would be added, etc., but not really talking about the process, what happens if the planned matching TC39 proposal doesn't succeed (which was not revealed in this initial proposal), etc. You say that it's optional, opt-in. However, if this becomes a Flow "language" feature, it's only optional for your own code. Any 3rd party code may or may not end up using these features, and we'd have to contend with them. It's about as "optional" as using classes in JS is. They're just part of the language. There isn't a valid version of JS with classes, and and equally valid version of JS that doesn't have them. I feel like calling this "optional" is a poor cop-out for the lack of community engagement from the Flow team. |
Yeah, if libdefs would use this syntax then it is no longer optional... and if it doesn't go through TC39 then it would be same thing as decorators all over again |
To comment the actual feature, whether it's an EcmaScript or a Flow feature - I don't see enums as such a useful feature even when I'm using TypeScript, since string literal union types pretty much solve the same problem. I guess I just don't see how setTheme(Theme.DARK) is any better than setTheme('DARK') as long as the string literal is type checked against union type like type Theme = 'LIGHT' | 'DARK' |
We could have a lint in flow-typed preventing using enum syntax in libdefs. And there shouldn't be much need for it anyways: Libdefs are usually written for standard JS (or TS in some cases) and since standard JS does not have enums, libdefs should not need to have them either. So in case of libdefs such syntax does not matter if we lint against it. On a personal note, I also definitely think that TC39 proposal should be filed as soon as possible to mitigate the fear of Flow not being just type system anymore. Anyways, in overall enums would be super nice feature! |
I'd love to have enum types in javascript! but I agree, an official TC 39 proposal as a first step would be better than a backdoor strategy through flow. @gkz not sure if you know, but there have been some (yet unofficial) attempts for enums, both are from current TC 39 members and unfortunately both haven't gone forward with the proposal yet. https://github.com/rwaldron/proposal-enum-definitions |
@PinkaminaDianePie @zeorin @goodmind @gkz |
@radoslawszymula If that is what you believe, my advice is to get enums into JS proper, first, then. Personally I am happy with
|
Flow Enums: Syntax
Flow is working on adding an enums language feature, for improved developer experience, performance, and safety. [EDIT: This would be an optional, opt-in feature, we would not change the default of not requiring any transformations other than stripping types]
Here, we examine the proposed syntax and grammar/ast specification for this feature (but do not examine runtime semantics or type-checking behavior, which are in development and will be shared at a later point).
edit: docs are now at https://flow.org/en/docs/enums/
The text was updated successfully, but these errors were encountered: