-
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
Callback function type checks don't work with overloads #8457
Comments
I believe this is a duplicate of #598 |
I think this is a different case because if interface KnockoutElement<T> {
// Getter
(): T;
// Setter
(value: T): void;
}
function readFile(finished: (contents: string) => string) { /*... */ }
var ko: KnockoutElement<number>;
readFile(ko); // throw an error correctly. Additionally, my filed case doesn't depend parameters. interface F {
(g: () => void): number; // if this line is removed, tsc gives a correct error.
(g: (i: () => number) => void): number;
}
var f: F;
f(i => h(i));
function h(i: () => string): string {
return i();
} So I think TypeScript should add a test of this case when fix this issue. |
You're right, this is different. The problem is that this code appears to be valid and it's not at all clear how to make it invalid. interface F {
(g: () => void): number;
(g: (i: (p: number) => number) => void): number;
}
var f: F;
f(g => h(g));
function h(i: (p: string) => string): string {
return i('');
} The code says that This code should really be written as interface F {
(g: (i: (p: number) => number) => void): number;
} or at the very least interface F {
(g: (i: () => number) => void): number;
(g: () => void): number; // if this line is removed, tsc gives a correct error.
} but it's unclear how we even detect these problems. |
I fixed my code a little. - f(g => h(g));
+ f(i => h(i)); |
@RyanCavanaugh Could you fix this? |
@falsandtru I'm not sure what you mean? |
@RyanCavanaugh Could you fix this problem? I feel this is a bug. |
Unfortunately it's a design limitation (we choose the first available overload successfully) with no clear fix. There's no reason to write a set of overloads that way, though, so the fix on your end should just be to do one of the suggested rewrites. Some advanced linting rule might be able to detect a set of "bad" signatures. |
I see, thanks for the answer... |
TypeScript Version:
master
Code
Expected behavior:
Actual behavior:
pass
The text was updated successfully, but these errors were encountered: