This makes the transformed function returns Promise<T> instead of Surprise<T, Dynamic>. Mainly because Promise has richer API, IMO. I use Promise everywhere now.
Since Promise<T> is essentially Surprise<T, Error>, that means errors thrown are wrapped in Error instances, and the data field gets extracted when the error is caught.
So if some codes throws a string, the catch block should also catch a string. (Closes #4)
If I understand correctly, the Error instance will not get destructured in the throw-catch waterfall but only at the end user's catch block, (correct me if I am wrong). If that is true, the performance impact should be minimal.
This makes the transformed function returns
Promise<T>
instead ofSurprise<T, Dynamic>
. Mainly because Promise has richer API, IMO. I use Promise everywhere now.Since
Promise<T>
is essentiallySurprise<T, Error>
, that means errors thrown are wrapped inError
instances, and thedata
field gets extracted when the error is caught. So if some codes throws a string, the catch block should also catch a string. (Closes #4) If I understand correctly, theError
instance will not get destructured in the throw-catch waterfall but only at the end user's catch block, (correct me if I am wrong). If that is true, the performance impact should be minimal.Seems passing the tests.