Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It checks fine for me.

    const testVal = "a"
Here, TypeScript infers that it is of type "string", and knows the value, so it is perfectly happy accepting it to ALSO be of type MyEnum. This is the problem- refactoring MyEnum means that testVal is not automatically updated, because the type is really "string" that just-so-happened to duck-type into MyEnum at the function call site.

On the other hand, if MyEnum were actually an enum rather than a union of strings, this problem wouldn't have happened.



Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: