You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Search Terms:
Enum, enum type checking, enum param Code
enumMyEnum{B=3}functionfoo(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.
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.
The text was updated successfully, but these errors were encountered:
TypeScript Version: 3.7.x-dev.201xxxxx
Search Terms:
Enum, enum type checking, enum param
Code
Expected behavior:
foo(2)
- should result inTS: 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.
The text was updated successfully, but these errors were encountered: