type Success = { data: T; error: null; }; type Failure = { data: null; error: E; }; export type Result = Success | Failure; export async function tryCatch(promise: Promise): Promise> { try { const data = await promise; return { data, error: null }; } catch (error) { return { data: null, error: error as E }; } }