You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
asyncfunctionfn(a: number){if(a<0){thrownewMyError()}returnotherFn(a)// known to return Promise<ComplexType>}const[err,data]=awaitgoTryRaw(fn(123))
data is typed as ComplexType, which is good.
err is typed as unknown, which is inconvenient.
Now as I know that fn throws MyError, I want to type the return value:
const[err,data]=awaitgoTryRaw<MyError>(fn(123))
err is typed as MyError
data is typed as unknown, which is inconvenient.
Sometypes ComplexType is not even exported as it may be a complex generic created inside a third party library, so it couldn't even be retrieved with ReturnType<...> escape hatch.
So basically developer is supposed to use goTryRaw without arguments and then cast error to proper type.
Ideally, there should be a way to provide error type but automatically infer return value type. I am not sure that elegant solution to this even exists, but wanted to report this concern nevertheless.
The text was updated successfully, but these errors were encountered:
Consider this:
data
is typed asComplexType
, which is good.err
is typed asunknown
, which is inconvenient.Now as I know that
fn
throwsMyError
, I want to type the return value:err
is typed asMyError
data
is typed asunknown
, which is inconvenient.Sometypes
ComplexType
is not even exported as it may be a complex generic created inside a third party library, so it couldn't even be retrieved withReturnType<...>
escape hatch.So basically developer is supposed to use
goTryRaw
without arguments and then cast error to proper type.Ideally, there should be a way to provide error type but automatically infer return value type. I am not sure that elegant solution to this even exists, but wanted to report this concern nevertheless.
The text was updated successfully, but these errors were encountered: