-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Function type union works unexpectedly #12404
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
This is type A = (...args: any[]) => any | (() => boolean); Is equivalent to: type A = (...args: any[]) => (any | (() => boolean)); Not: type A = ((...args: any[]) => any) | (() => boolean); Try: type AnyFn = (...args: any[]) => any;
declare const fn: (((...args: any[]) => any) | (() => boolean));
declare const fn2: (AnyFn | (() => boolean));
fn(1, 2, 3);
fn2(1, 2, 3); I tested it, works fine. Be more careful with operator precedence, it bites bad 🙀 |
@alitaheri Thanks. Good call on the precedence, and you're right that with your revised code the two declarations behave equivalently. However, now both function calls give an error! So I guess the issue is with how the two types are being unioned? I'll update the OP accordingly. |
Duplicate of #7294 ? |
Seems like it might be, though I'll wait for @RyanCavanaugh to confirm before closing this. |
Looking at #7294 more closely, they're definitely the same problem conceptually. I'm gonna give this a close. |
TypeScript Version: nightly (2.2.0-dev.20161121)
Code
Expected behavior:
The call to
fn(1, 2, 3)
should succeed, as it should match the(...args: any[]) => any
part of the union.Actual behavior:
I get the error: "Supplied parameters do not match any signature of call target."
The text was updated successfully, but these errors were encountered: