Skip to content
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

Is it possible to use $Values for enums, without using Object.freeze? #5465

Closed
bluepnume opened this issue Dec 5, 2017 · 2 comments
Closed

Comments

@bluepnume
Copy link

bluepnume commented Dec 5, 2017

The latest flow release shows the following example:

const Enum = Object.freeze({
  X: 'x',
  Y: 'y',
});
type EnumT = $Values<typeof Enum>
('a': EnumT); // Fails

Is it possible to do this without the run-time Object.freeze()? This raises browser-support and performance concerns.

I tried this but it didn't work:

type FrozenEnum = { +[string]: string }
const Enum : FrozenEnum = {
  X: 'x',
  Y: 'y',
};
type EnumT = $Values<typeof Enum>
('a': EnumT); // Doesn't fail but should

How can I mark the Enum as being frozen, without using Object.freeze?

@zerobias
Copy link
Contributor

zerobias commented Dec 9, 2017

@bluepnume Not exactly what you want to see, but you might not need the runtime to declare something. Thanks to comment syntax this works as well

const Enum = /*::Object.freeze(*/{
  X: 'x',
  Y: 'y',
}/*::);*/
type EnumT = $Values<typeof Enum>
('a': EnumT); // Fails

@TrySound
Copy link
Contributor

I guess this can be closed in favor of #627

/cc @vkurchatkin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants