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

Expected 1-3 arguments, but got 2 #19220

Closed
ghost opened this issue Oct 16, 2017 · 14 comments
Closed

Expected 1-3 arguments, but got 2 #19220

ghost opened this issue Oct 16, 2017 · 14 comments
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Fixed A PR has been merged for this issue Good First Issue Well scoped, documented and has the green light Help Wanted You can do this

Comments

@ghost
Copy link

ghost commented Oct 16, 2017

TypeScript Version: 2.6.0-dev.20171015

Code

declare function f(x: number): number;
declare function f(x: number, y: number, z: number): number;

f(1, 2);

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.

@ghost ghost added Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging labels Oct 16, 2017
@mhegazy mhegazy added this to the Community milestone Oct 16, 2017
@mhegazy mhegazy added Help Wanted You can do this Good First Issue Well scoped, documented and has the green light labels Oct 16, 2017
@lmcarreiro
Copy link

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 Expected 1 or 3 or 4 or 5 or ... or N arguments, but got 2. ???

@ghost
Copy link
Author

ghost commented Oct 16, 2017

Based on existing error messages, it would be ideal to say Expected 1 or at least 3 arguments, but got 2..
Of course, doing this in a localizable way without defining too many different diagnostics will be more difficult; might be better to use commas instead of or (except for the last one) so that the template would be Expected {0} or at least {1} arguments and fill in {0} with a comma-separated list if necessary.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Oct 16, 2017

Consider something like No overload expects {0} arguments. The most likely overloads that match expect either {1} arguments or at least {2} arguments.

@ghost
Copy link
Author

ghost commented Oct 16, 2017

@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".

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Oct 17, 2017

Yup, that's what I should've been explicit about, thanks for clarifying. 😃

@sandersn
Copy link
Member

Note that this has occurred at least once in real code: DefinitelyTyped/DefinitelyTyped#19119.

@gusdecool
Copy link

this also happened on https://www.npmjs.com/package/@types/urijs library when we are calling addQuery() with 2 arguments

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

@sandersn
Copy link
Member

That's because addQuery only expects 1 argument:

    interface URI {
        absoluteTo(path: string): URI;
        absoluteTo(path: URI): URI;
        addFragment(fragment: string): URI;
        addQuery(qry: string): URI;
        addQuery(qry: Object): URI;
        // ......

Maybe @types/urijs needs to be updated.

@NaridaL
Copy link
Contributor

NaridaL commented Jan 27, 2018

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])

@jakearchibald
Copy link

I ran into this too: https://goo.gl/ufcpDP.

@durjoy28
Copy link

durjoy28 commented May 9, 2018

Error TS2554, expected argument 2 but got 1.
How I can solve it?
sign(myForm){
if(myForm.valid){
this.af.auth.createUserWithEmailAndPassword({
email:this.email,
password:this.password
}).then(
(success)=> {
console.log(success);
this.router.navigate(['/login'])
}).catch(
(err)=> {
console.log(err);
this.error=err;
})

@ghost
Copy link
Author

ghost commented May 9, 2018

@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.

Kr4pper pushed a commit to Kr4pper/TypeScript that referenced this issue May 20, 2018
Kr4pper pushed a commit to Kr4pper/TypeScript that referenced this issue Jul 6, 2018
Kr4pper pushed a commit to Kr4pper/TypeScript that referenced this issue Jul 11, 2018
sandersn pushed a commit that referenced this issue Jul 12, 2018
* 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
@mhegazy mhegazy modified the milestones: Community, TypeScript 3.0.1 Jul 12, 2018
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jul 12, 2018
@shubhamyugtia001
Copy link

this only happens when you build the project.
for serve, project run smoothly.
there should be reason behind this at all for giving number of argument in a function
ERROR in src\app\component\crm\smslist\list\list.component.html(11,19): : Expected 1 arguments, but got 2.

@DanielRosenwasser
Copy link
Member

This isn't a support forum and if you think you've found a bug you should file that separately.

@microsoft microsoft locked and limited conversation to collaborators Jan 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Fixed A PR has been merged for this issue Good First Issue Well scoped, documented and has the green light Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

9 participants