⬅️ FEM TypeScript Fundamentals
Exhaustiveness checking
- Exhaustive” means “considering all possibilities”
- The
true
value isn’t useful to us at runtime, but we have to return something in order to use exhaustiveness checking. - Generally, we associate exhaustiveness checking with
switch
. However, it works withif
as well. - In TypeScript, providing a
default:
inside of ourswitch
effectively disables exhaustiveness checking.
So in summary when using switch
:
- Put the
switch
inside of a function where each casereturn
s. - Give the function an explicit return type.
- Don’t add a
default
unless you’re very sure that you need one.