-
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
Expected 1-3 arguments, but got 2 #19220
Comments
But what if it was: declare function f(x: number): number;
declare function f(x: number, y: number, z: number): number;
declare function f(x: number, y: number, z: number, a: number): number;
declare function f(x: number, y: number, z: number, a: number, b: number): number;
...
declare function f(x: number, y: number, z: number, a: number, b: number, ...): number;
f(1, 2); The message would be |
Based on existing error messages, it would be ideal to say |
Consider something like |
@DanielRosenwasser Good, assuming that "most likely" would mean the next lowest and next highest numbers of arguments. So if overloads accepted 1, 2, or 5 arguments and you provide 3 or 4, say "2 or 5". |
Yup, that's what I should've been explicit about, thanks for clarifying. 😃 |
Note that this has occurred at least once in real code: DefinitelyTyped/DefinitelyTyped#19119. |
this also happened on import * as URI from 'urijs';
const path = new URI(`/some-url`);
path.addQuery('pickUpCoordinate', 'foo-query'); // this will throw TS2554 expected 1 argument but got 2 arguments |
That's because interface URI {
absoluteTo(path: string): URI;
absoluteTo(path: URI): URI;
addFragment(fragment: string): URI;
addQuery(qry: string): URI;
addQuery(qry: Object): URI;
// ...... Maybe |
Very similar issue: // lib ArrayConstructor sig for reference
interface ArrayConstructor {
from<T>(iterable: Iterable<T> | ArrayLike<T>): T[];
from<T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
}
// [ts] Expected 1-3 arguments, but got 1.
Array.from<number, number>([1, 2, 3]) |
I ran into this too: https://goo.gl/ufcpDP. |
Error TS2554, expected argument 2 but got 1. |
@durjoy That probably depends on the library you're using. Look for a help forum for that -- it's probably not a bug in the compiler. |
* Added reference test case and diagnostics message * Adjusted arity checks to account for non-contiguous overloads * Code cleanup, baseline not yet commited * Accepted test baselines and minor implementation changes * Cleaned up baseline tracking the now renamed arity check test * Add range response when range contains only 2 values * Added recent baseline * Refined arity error messages when available overloads can be grouped * Rolled back code formatting * WIP cleanup needed in a few edge cases * Finished adding new more descriptive error messages * Code cleanup * Added simplified version of bugfix for #19220 * Rebased onto master * Removed whitespace after type assertion * Code review simplifications * Use correct diagnostic name * Code review changes and simplification of diagnostic message * Revert formatting changes
this only happens when you build the project. |
This isn't a support forum and if you think you've found a bug you should file that separately. |
TypeScript Version: 2.6.0-dev.20171015
Code
Expected behavior:
Expected 1 or 3 arguments, but got 2.
Actual behavior:
src/a.ts(4,1): error TS2554: Expected 1-3 arguments, but got 2.
The text was updated successfully, but these errors were encountered: