Promise

2025-09-01 16:23:20

统一使用 try/catch

try-catch.ts
test.ts
          async function 
tryCatch
<
T
>(
promise
:
Promise
<
T
>):
Promise
<[null,
T
] | [
Error
, null]> {
try { const
res
= await promise
return [null,
res
] as [null,
T
]
} catch (
error
) {
return [
error
as
Error
, null] as [
Error
, null]
} }
© 2021-2026 sunshj's Blog