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
{{ message }}
Repository navigation
Argument becomes implicit any when a void-returning overload follows a non-void-returning signatureΒ #48088
I think the overloads are needed -- it's either them or an overly long and confusing conditional generic type. The test function can either take in an input or return a Promise. Adjusting the snippet a little to look more like the Mocha types [playground link]:
Any return type is assignable to a return type of void, including promises. And you couldn't prevent this at runtime either because you have no way to know that the user passed in an async function without actually calling it and observing its return value.
the only reason it's an error now is because it's an implicit any, like the first call
Ha, that's fair.
But I think this issue is still valid, that the becoming an implicit any is an undesirable behavior (dating back a while) because now there's no way to accurately represent the Mocha types.
A bit of a tangent but () => void accepting any return type is usually desirable (see FAQ link above), but I do sometimes wish we could write () => undefined for the few cases where you really want to exclude value returns and not then be forced to write an explicit return undefined;.
I'm not quite sure what can be done here. Overload resolution behavior is extremely baked-in and it's going to be tough to change it. PRs that don't break other stuff are welcome π
Ryan Cavanaugh (@RyanCavanaugh) I thought this issue wasnβt about overload resolution, so much as contextual typing of callback parameters failing in the mere presence of overloads.
The problem is that we assign a contextual type during overload resolution, and don't have an acceptable way to "undo" that. Prior attempts to fix this have failed for one reason or another.
Activity
MartinJohns commentedon Mar 2, 2022
I think this is due to: https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#implicit-any-error-raised-for-un-annotated-callback-arguments-with-no-matching-overload-arguments
Is the first overload really needed? The code will behave the same without it.
JoshuaKGoldberg commentedon Mar 2, 2022
I think the overloads are needed -- it's either them or an overly long and confusing conditional generic type. The
testfunction can either take in an input or return aPromise. Adjusting the snippet a little to look more like the Mocha types [playground link]:I.e. you can't provide an
asyncfunction that also takes in & calls adoneparameter.fatcerberus commentedon Mar 2, 2022
Assuming the inference worked, you wouldn't get the expected error on the third call (the only reason it's an error now is because it's an implicit
any, like the first call), because it would still match the second overload, per https://github.com/microsoft/TypeScript/wiki/FAQ#why-are-functions-returning-non-void-assignable-to-function-returning-void:Any return type is assignable to a return type of
void, including promises. And you couldn't prevent this at runtime either because you have no way to know that the user passed in an async function without actually calling it and observing its return value.JoshuaKGoldberg commentedon Mar 2, 2022
Ha, that's fair.
But I think this issue is still valid, that the becoming an implicit any is an undesirable behavior (dating back a while) because now there's no way to accurately represent the Mocha types.
fatcerberus commentedon Mar 2, 2022
A bit of a tangent but
() => voidaccepting any return type is usually desirable (see FAQ link above), but I do sometimes wish we could write() => undefinedfor the few cases where you really want to exclude value returns and not then be forced to write an explicitreturn undefined;.RyanCavanaugh commentedon Mar 3, 2022
I'm not quite sure what can be done here. Overload resolution behavior is extremely baked-in and it's going to be tough to change it. PRs that don't break other stuff are welcome π
JoshuaKGoldberg commentedon Mar 3, 2022
Hmm, now that #29374 is in I was looking forward to making another multi-year pull request. Great...!
fatcerberus commentedon Mar 3, 2022
Ryan Cavanaugh (@RyanCavanaugh) I thought this issue wasnβt about overload resolution, so much as contextual typing of callback parameters failing in the mere presence of overloads.
RyanCavanaugh commentedon Mar 3, 2022
The problem is that we assign a contextual type during overload resolution, and don't have an acceptable way to "undo" that. Prior attempts to fix this have failed for one reason or another.
See also #11936