Skip to content

Enum type checking seems broken #39187

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
nbabanov opened this issue Jun 22, 2020 · 3 comments
Closed

Enum type checking seems broken #39187

nbabanov opened this issue Jun 22, 2020 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@nbabanov
Copy link

nbabanov commented Jun 22, 2020

TypeScript Version: 3.7.x-dev.201xxxxx

Search Terms:
Enum, enum type checking, enum param
Code

enum MyEnum {
	B = 3
}

function foo(param: MyEnum) {    
}

foo(MyEnum.B); // This should be the only working example.

foo('asdfasdf'); // This does not work, which is good.

foo(2); // This should also not work, but it does. :(

Expected behavior:
foo(2) - should result in TS: 2345 argument of type number is not assignable to a parameter of type MyEnum..
Actual behavior:
No errors.

Playground Link: demo
Related Issues: None.

I think the actual behaviour of TS makes using enums almost pointless to me. If I want a stricter type checking I have to manually create an union type or a function which returns union types.

@MartinJohns
Copy link
Contributor

Duplicate of #32690 / #30629.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 22, 2020
@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.

@nbabanov
Copy link
Author

nbabanov commented Apr 6, 2023

This is fixed in TypeScript v5!!! 🎊

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