-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Argument becomes implicit any when a void-returning overload follows a non-void-returning signature #48088
Comments
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. |
I think the overloads are needed -- it's either them or an overly long and confusing conditional generic type. The declare const it: {
(test: () => Promise<void>): void;
(test: (done: () => void) => void): void;
}
it((done) => {
done();
});
it(async () => {
// ...
});
// @ts-expect-error
it(async (done) => {
done();
}); I.e. you can't provide an |
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 declare const it: {
(test: () => Promise<void>): void;
(test: (done: () => void) => void): void;
}
it((done: () => void) => {
done();
});
it(async () => {
// ...
});
it(async (done: () => void) => {
done();
}); Any return type is assignable to a return type of |
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 |
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 π |
Hmm, now that #29374 is in I was looking forward to making another multi-year pull request. Great...! |
@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. See also #11936 |
Bug Report
π Search Terms
overload argument type signature
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
π Expected behavior
No type error. The
input
parameter is typestring
and should be resolved as such.For more context, see DefinitelyTyped/DefinitelyTyped#59075.
The text was updated successfully, but these errors were encountered: