Inconsistent type resolution when resolving a Promise in a generic context #46543
Labels
Fix Available
A PR has been opened for this issue
Needs Investigation
This issue needs a team member to investigate its status.
Rescheduled
This issue was previously scheduled to an earlier milestone
Milestone
Bug Report
🔎 Search Terms
promise generic return type resolution wrapper await resolve
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
I use a library which exports generic functions in shapes like
findMany
(see code sample). Generally these functions accept one argument and map to some return type depending on the arguments type. This works fine and is no issue at all.My aim was to add a wrapper arround such a generic function to do some extra work before or after calling it e.g.:
When you look at the code sample you can see two wrappers:
wrapperWorking
andwrapperNotWorking
. The only difference between them is thatwrapperNotWorking
is anasync
function thatawait
s the result offindMany
first before passing it to thereturn
.Although these functions are essentially the same the typings behave differently. To be precise the unexpected behaviour is in this line:
result
resolves immediatly to the value1
, butargs
is generic and it should not resolve to a definite value here. For this reasonwrapperNotWorking
is always returningPromise<1>
, whilewrapperWorking
returns the correct type. (seemain
for examples and differences)🙂 Expected behavior
The type of
result
should be:and
wrapperNotWorking
should returnPromise
's accordingly.Otherwise it's not conistent and confusing.
The text was updated successfully, but these errors were encountered: