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

TypeCheck: any number can be assigned to number-value enums #49967

Closed
git9am opened this issue Jul 20, 2022 · 2 comments
Closed

TypeCheck: any number can be assigned to number-value enums #49967

git9am opened this issue Jul 20, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@git9am
Copy link

git9am commented Jul 20, 2022

Bug Report

πŸ”Ž Search Terms

enum, number

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about enums

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

enum TypeA {
    A = 0,
    B = 1,
    C = 2,
}

const valueA1: TypeA = 4; // <-- no error
const valueA2: TypeA = '4';

enum TypeB {
    A = '0',
    B = '1',
    C = '2',
}

const valueB1: TypeB = '4';
const valueB2: TypeB = 4;

πŸ™ Actual behavior

The number can be assigned to an enum without errors.

πŸ™‚ Expected behavior

Errors.

@MartinJohns
Copy link
Contributor

Duplicate of #26362, which provides plenty of reasoning for this behaviour. Used search terms: enum number in:title

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jul 20, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants