Promise
2025-09-01 16:23:20
统一使用 try/catch
try-catch.ts
test.ts
async function tryCatch<T>(promise: Promise<T>): Promise<[Error | null, T | null]> {
try {
const res = await promise
return [null, res] as [null, T]
} catch (error) {
return [error as Error, null] as [Error, null]
}
}