5 ms·
Using TypeScript's user defined type guards instead of a switch looks promising here, inside the 'if' the actions are type checked.
by DougBTX 11y ago
Using TypeScript's user defined type guards instead of a switch looks promising here, inside the 'if' the actions are type checked.
- masklinn 11y agoOr better, use Elm (or something similar) and tagged unions. That way you get type-checking and exhaustive-checking of your message types. You still have a big match (~switch/case) but now the compiler yells at you if you've forgotten to handle a message tag or if you're not unpacking the right types from it.