-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Types for async functions do not handle void
assignments like normal ones
#33420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There are two rules we have in place governing the above:
This creates this annoying inconsistency where even though function statement/expressions with annotated returns of |
This has caused me pain already when writing typings for miniSphere. Generally speaking I like the rule where a |
This does seem a bit tricky though: if we made the And then even if it is... what about when the type parameter is contravariant? Or invariant? Does variance affect it at all? It’s a pretty big can of worms. |
Tbh, I think |
I don’t know, I think it’s kind of elegant right now that
Where “you” = programmer, “I” = type system. |
I've noticed that void doesn't behave as expected for the following circumstance either: This should throw an error because type BasicFn = () => void
// Should throw an error but doesn't
const x: BasicFn = () => () => console.log('hello') This bug caused me to spend a multiple hours trying to figure out what I was doing wrong. It's not easy spotting that |
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
Code
Expected behavior:
Generally speaking, all of them should be an error, or all of them shouldn't be.
Actual behavior:
We have a special "function returning void" rule that allows
() => ""
to be assignable to() => void
, but this doesn't carry thru to async scenarios, so aasync () => ""
is not assignable to a() => Promise<void>
.Playground Link
The text was updated successfully, but these errors were encountered: