Effect fixes your TypeScript · Part 1
Your TypeScript functions are lying to you
A return type of Promise of User hides that getUser can throw UserNotFound, DbError or ParseError. With Effect, the errors are part of the type. Forget to handle one and the compiler tells you. Handle one and it disappears from the type.
Comment below: How do you document errors today?
Effect fixes your TypeScript: a series on the bugs you already ship, and how Effect makes them impossible. All code is real Effect v4 and was compiled before it went on screen. https://effect.website
Transcript
This TypeScript function is lying to you. It says it returns a Promise<User>, but it can throw user not found, database down, or invalid JSON, and your type system has no idea. Neither does the next dev who calls it. Neither do you 6 months from now. In Effect, the same function returns an Effect<User, UserNotFound | DbError | ParseError>. The errors are in the type. Forget to handle one, red squiggle. Handle one, it disappears from the type. That's the real best practice. Failure is part of your API, not a surprise. But how do you actually handle those errors without try/catch? Part two, how do you document errors today? Tell me in the comments.




