8000 Rule proposal: Don't allow literal numbers as values when an enum value is expected. · Issue #4186 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

Rule proposal: Don't allow literal numbers as values when an enum value 8000 is expected. #4186

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

Closed
ChocolateLoverRaj opened this issue Nov 19, 2021 · 1 comment
Labels
duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@ChocolateLoverRaj
Copy link

Description

What I like about enums:

  • There is text to describe what the number means
  • You can change the value of enum Code { A = 'something else' }, and Code.A will then equal the new value
  • You know the range of the enum values. For example, 1 or above doesn't make sense in enum Code { A }

Except TypeScript allows passing numbers and strings without specifying Enum.VALUE. This is confusing and in my opinion defeats the point of an enum.

Fail

enum Code { A }
const code: Code = 0

Pass

enum Code { A }
const code: Code = Code.A
@ChocolateLoverRaj ChocolateLoverRaj added enhancement: new base rule extension New base rule extension required to handle a TS specific case package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Nov 19, 2021
@bradzacher
Copy link
Member

Duplicate of #308

@bradzacher bradzacher added duplicate This issue or pull request already exists and removed triage Waiting for team members to take a look enhancement: new base rule extension New base rule extension required to handle a TS specific case labels Nov 19, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants
0