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
… and if ApiResponse<string> in the example above turns out to resolve to string | Promise<string>, you cannot use async keyword anymore, and forced to fallback to .thens and .catches if working with promises.
… because, while it works, it also requires for you to a) know the implementation of ApiResponse (which you shouldn’t know), and b) navigate your way through unreasonable TypeScript compiler errors that don’t bring any value.
Is this correct?
If it is, then I agree with the proposal. Not only that, I would actually go a bit further, and propose to remove the distinction between “bare” and promise-wrapped values in return signatures of async functions altogether. Meaning that these signatures:
asyncfunctiondoStuff(): string{
asyncfunctiondoStuff(): Promise<string>{
… should be considered indistinguishably identical.
The text was updated successfully, but these errors were encountered:
Originally posted by @parzhitsky in #33595 (comment)
Okay, so, if I understand correctly, you are saying that this is wrong (or weird at least):
… and so is this:
But there are situations when you can’t really control the structure of the type union, since you don’t create it, like here:
… and if
ApiResponse<string>
in the example above turns out to resolve tostring | Promise<string>
, you cannot useasync
keyword anymore, and forced to fallback to.then
s and.catch
es if working with promises.But you also cannot do this:
… because, while it works, it also requires for you to a) know the implementation of
ApiResponse
(which you shouldn’t know), and b) navigate your way through unreasonable TypeScript compiler errors that don’t bring any value.Is this correct?
If it is, then I agree with the proposal. Not only that, I would actually go a bit further, and propose to remove the distinction between “bare” and promise-wrapped values in return signatures of
async
functions altogether. Meaning that these signatures:… should be considered indistinguishably identical.
The text was updated successfully, but these errors were encountered: