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

refactor: remove enums in favor of const objects #2741

Merged
merged 1 commit into from Feb 19, 2021

Conversation

nbbeeken
Copy link
Contributor

@nbbeeken nbbeeken commented Feb 16, 2021

Changes remaining enums to const objects and exports all user relevant
"enums" from index.ts. Enums are frozen to ensure they remain static.
Added a lint rule to prevent further enums.
Corrected mistake in sourcemap emit settings.

NODE-2973

Changes remaining enums to const objects and exports all user relevant
"enums" from index.ts. Enums are frozen to ensure they remain static.
Added a lint rule to prevent further enums.
Corrected mistake in sourcemap emit settings.
@nbbeeken nbbeeken marked this pull request as ready for review February 17, 2021 17:18
Copy link
Contributor

@emadum emadum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I recall there being some discussion about enums, but can you remind me what motivated this change?

@nbbeeken
Copy link
Contributor Author

There were a few reasons, one was const enums can't be used by users since they disappear at compile time, another was that an enum forces you to use the enum even if you pass in an equivalent value.

enum Weekday { Monday = 1, ... };
function printDay(day: Weekday);

Our union of the possible values pattern would permit you to pass in 1 directly for example. This comes up when we have a variable that is of type number and we've done a check to ensure its one of the acceptable values but there's still a type error unless you cast etc.

@nbbeeken nbbeeken merged commit d52c00e into 4.0 Feb 19, 2021
@nbbeeken nbbeeken deleted the NODE-2973/enum-removal branch February 19, 2021 21:56
ljhaywar pushed a commit that referenced this pull request Nov 9, 2021
Changes remaining enums to const objects and exports all user relevant
"enums" from index.ts. Enums are frozen to ensure they remain static.
Added a lint rule to prevent further enums.
Corrected mistake in sourcemap emit settings.

NODE-2973
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants