Re:Why Would Anyone Need JavaScript Generator Functions?
by couchand on Monday November 07, 2022 @11:38AM
(#33508143)
And of course, there is no free lunch. You run smack into the expression problem here.
The question is: do you have more places that check your conditions than types of options? Are you more likely to add a new check (and need to verify exhaustiveness) or add a new option (and need to modify every check)?
Some languages support exhaustive switches (typescript has a way to do this), but oftentimes the better solution is to consolidate all of these switches into an object, or a set of objects that share an interface. That way all of the switch statements become function calls or property accesses, and the type checker can warn you at time of creation of the new object if you're not providing all of the functionality the rest of the code will require.