Stop Throwing, Start Returning: Why TypeScript Needs the Result Pattern
· 10 min read
You've written this code a hundred times:
try {
const user = await fetchUser(id);
const posts = await fetchPosts(user.id);
const rendered = renderProfile(user, posts);
return rendered;
} catch (error) {
// what is error? string? Error? AxiosError? Who knows.
console.log("something went wrong", error);
}
And every time, you've made the same bet: that nothing unexpected will end up in that catch block.
Let's talk about why that bet keeps losing.
