Skip to content

Parameters<FnInterface> return only last overload arguments type #34432

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
iamolegga opened this issue Oct 15, 2019 · 2 comments
Closed

Parameters<FnInterface> return only last overload arguments type #34432

iamolegga opened this issue Oct 15, 2019 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@iamolegga
Copy link

iamolegga commented Oct 15, 2019

TypeScript Version: 3.7.x-dev.201xxxxx ("nightly" on http://www.typescriptlang.org/play/)

Search Terms:
typescript parameters of overloading function interface

Code

interface LogFn {
  // move lines oreder to see different behavior 
  (msg: string, ...args: any[]): void;
  (obj: object, msg?: string, ...args: any[]): void;
}

class Logger {
  private readonly logger!: LogFn;

  log(...args: Parameters<LogFn>) {
    this.logger(...args);
  }
}

const loggerInstance = new Logger();

loggerInstance.log('test');
                   ^^^^^^ Argument of type '"test"' is not assignable to parameter of type 'object'.(2345)
loggerInstance.log({});

Expected behavior:
Parameters<FnInterface> should return all types of arguments

Actual behavior:
Parameters<FnInterface> return only last overload arguments type

Playground Link: http://www.typescriptlang.org/play/?ts=Nightly&ssl=1&ssc=1&pln=19&pc=1#code/JYOwLgpgTgZghgYwgAgDIHsDmAxEyDeAUMsgPSnIC26AbigDagQDOy6UEAJtMmOsswgpOwGDGgRwyAEYQAFnBrB2yYsgAUlZpgBcAsFFCYANMgB0FuFEzM9cEAE8A2gF0AlHprpgnANxr1dGkAKz0g4IgEMFMtTAB+PWYDI1MLMysbO0dXD2QvH38AX0JCBHo4ZlYMTEweIhIAB0MaOEhkDjhOdBB6B2R6LFqoAEI9atx-NQHMdTSM22QABSs4SghIKGYAHnGQAD43AjUSMDlgZjNpodnLa2Y3fxJi4tLupP7B6ABJECT7JGQAF5kCAIAB3NCfKDqB4lK7fX5gf4QS5YdQAckgSXRsPhUB+fxASFRM3whVhQA

Related Issues:

@jack-williams
Copy link
Collaborator

Duplicate of #29732

@jack-williams jack-williams marked this as a duplicate of #29732 Oct 15, 2019
@ahejlsberg ahejlsberg added the Duplicate An existing issue was already created label Oct 15, 2019
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants