Re:Hegel – An advanced static type checker for JavaScript
by zdragnar on Thursday October 13, 2022 @11:51AM
(#33192681)
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.
Do you mean it doesn't compile, because it doesn't. You need to write either
or The latter passes typechecking with invalid values, both change automatically for me if I refractor the symbol values in VS Code.