Skip to content

Instantly share code, notes, and snippets.

@fernandohmg
fernandohmg / try-catch.ts
Created February 28, 2025 07:46 — forked from t3dotgg/try-catch.ts
Theo's preferred way of handling try/catch in TypeScript
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};