2 ms·
I’ll try: Returning a “Result” with union discrimination on the “success” is far superior to throwing in Typescript in my experience { success: false, reas
by nip 2y ago
I’ll try:
Returning a “Result” with union discrimination on the “success” is far superior to throwing in Typescript in my experience
{ success: false, reason: “user_already_exists” } | { success: true, data: { user_id: string }
- By design you are forced to “deal” with the sad path: in order to get to the data, you must handle the error state
- Throwing is not type-safe: you cannot know at build time whether you are handling all thrown errors