Advice on using Effect for only error-as-value and patter matching
effecttypescript✅Solved!match
Hey guys,
This week I will try to introduce Effect to my colleagues at work. We maintain large and legacy TS API microservices. The team is made up of people with little to no exposure to functional programming.
We already reached the conclusion that using exceptions for error handling is a mistake and we agreed to move to an error-as-value approach, either with a library like neverthrow or an in-house error type.
We also want some form of exhaustive pattern matching in our handlers to ensure that if a new error is introduced we get a type error.
I have been experimenting with Effect myself. I like it and I think it fits our needs. However, I do not think I will be able to convince people to go all in. Effect pipe and generators will look alien to most. If instead I present Effect as an all-in-one solution that could replace neverthrow, ts-pattern, lodash, zod, and others, I think it will be better received. We can always move toward the full Effect style later once we have more buy-in.
For the presentation, I am trying to show a solution with the following characteristics: - functions return errors as values - errors are tagged - callers can exhaustively pattern match on returned types - works even with inferred return types
But that solution feels odd, since it uses a custom TaggedClass instead of a proper return type like Either or Exit. I tried using Either as well, but that approach requires manually typing the return type of a1_sync: