Today I’m sharing a little trick that I like to use to make switch statements cleaner and more type-safe. Happy to hear other ideas!
Today I’m sharing a little trick that I like to use to make switch statements cleaner and more type-safe. Happy to hear other ideas!
Generally, I would recommend against throwing in the
default
case, since it will actually reduce your type safety (exceptions bypass all your other types). But I learned that with another clever trick this can be avoided, giving both runtime and compile time safety: https://exploringjs.com/tackling-ts/ch_enums.html#exhaustiveness-checks