Lightweight, progressive, type-safe error handling for TypeScript. Bridge the gap between try/catch and heavy functional programming with zero-overhead success paths.
Success values are returned directly with no wrapping. Error objects only created when needed.
// Success: Direct return
const result = trySync(() => parse(data));
// result is ParsedData | TryError
Start simple with basic error handling, add complexity as needed. No need to rewrite existing code.
// Start simple
const result = trySync(() => operation());
// Add retry, timeout, etc. later
Full type inference, discriminated unions, and strict null checks. Built for TypeScript developers.
if (isTryError(result)) {
// result is TryError
} else {
// result is success type
}
try {
const response = await fetch("/api/user");
const user = await response.json();
return user;
} catch (error) {
console.error("Something failed:", error);
return null;
}
const result = await tryAsync(async () => {
const response = await fetch("/api/user");
return response.json();
});
if (isTryError(result)) {
console.error("API failed:", result.message);
return null;
}
return result; // Type-safe success value