Skip to content
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

Incorrect error message when overloaded function is called with invalid parameter #12313

Closed
bjouhier opened this issue Nov 16, 2016 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@bjouhier
Copy link

TypeScript Version: 2.0.3

Code

function foo(x: 'a'): void;
function foo(x: 'b'): void;
function foo(x: 'c'): void;
function foo(x: 'a' | 'b' | 'c') {}

foo('d');

Expected behavior:

Error: Argument of type '"d"' is not assignable to parameter of type '"a" | "b" | "c"'

Actual behavior:

Error: Argument of type '"d"' is not assignable to parameter of type '"c"'
@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Nov 16, 2016
@RyanCavanaugh
Copy link
Member

The implementation signature is not part of the type. If this function were in a declaration file you'd just see

function foo(x: 'a'): void;
function foo(x: 'b'): void;
function foo(x: 'c'): void;

It wouldn't be feasible to show a synthesized union type of all the possible first argument types -- some functions have dozens of overloads and that type would be huge (not to mention not even correct)

@bjouhier
Copy link
Author

Would be nice to have an indication that the parameter has overloads. Something like:

Error: Argument of type '"d"' is not assignable to parameter of type '"c"', nor to any of its overloads.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants