loading...

re: Opinionated React - Use Status Enums Instead of Booleans VIEW POST

FULL DISCUSSION
 

Tagged unions in TypeScript do the same thing, but also allow you to attach a response or error message etc. I love them in combination with switch statements and exhaustive function returns, but a lot of developers react negatively to exhaustive switch statements that handle every possible case. They see them as verbose. I see them as the compiler detecting not only existing logic bugs, but preventing future issues that can arise. Algebraic data types are truly amazing if you embrace them.

 

This sounds interesting. Do you have any examples of this pattern you'd like to share? I'd like to learn more!

I personally have not used tagged unions yet. I'll look into them!

code of conduct - report abuse