Open georeith opened 3 years ago
It cannot be an error to union two different types, so the error would have to be at the use site. Can you propose when and where the error should be issued?
Two more things:
You could also avoid your particular problem if enum values of different types were not assignable to each other. I believe string enums behave this way.
Suggestion
🔍 Search Terms
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
I would like a configurable option to prevent the union of enums with same values.
📃 Motivating Example
Consider the following example:
There is no warning from TypeScript that
isHorizontalEdge
may return true when passed aVerticalEdge
.This could even occur with string enums if the developer is not careful:
Warning against unioning enums with same values would prevent this situation and tell the developer that they need to give their enums distinct values or the union can not be narrowed later as it may lead to runtime errors.
💻 Use Cases
Currently it is up to the developer to be aware of this and carefully check their enums do not overlap when unioning them into a type (the developer may not even be aware this enum is later used in an union), the configuration operation would allow you to opt out of this behaviour entering your codebase.