-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Description
Which @angular/* package(s) are relevant/related to the feature request?
No response
Description
If you're using an enum as the switch value, you cannot guarantee that all properties of that enum have been checked. You can do this with a normal TS switch case by checking that the value is a never
in the default case. This won't be possible in NgSwitch
, but you can still do a runtime check to make sure each of the enum's values have been checked.
Proposed solution
Create a CheckExhaustive
directive. Store the ngSwitchCase
s within NgSwitch
and allow the CheckExhaustive
directive to check the enum against the stored switch cases. Throw an error if a case is missed.
Alternatives considered
I tried making my own external directive and tried using the _caseCount
value to compare the number of enum properties to. The problem there was that I could potentially add multiple of the same switch cases, which make the count unreliable to evaluate whether it exhaustively checks all the properties of the enum.