Skip to content

Instantly share code, notes, and snippets.

View aswnss-m's full-sized avatar
🌎
Working

Aswin Lal M aswnss-m

🌎
Working
View GitHub Profile
@aswnss-m
aswnss-m / tryCatch.ts
Created November 10, 2025 08:49
Better try catch which can handle async function as well. Picked from theo's trycatch gist
// Define the success/failure tuple types
export type OperationSuccess<T> = readonly [data: T, error: null];
export type OperationFailure<E> = readonly [data: null, error: E];
export type OperationResult<T, E> = OperationSuccess<T> | OperationFailure<E>;
// Define the allowed operation types
/**
* Checks if the value is a Promise or "Thenable"
* @param value - The value to check
* @returns True if the value is a Promise, false otherwise