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

argument types inference breaks for specific object literal method syntax #26629

Closed
billba opened this issue Aug 23, 2018 · 3 comments
Closed
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@billba
Copy link
Member

billba commented Aug 23, 2018

TypeScript Version: 3.1.0-dev.20180823

Search Terms: object literal method argument

Code

function goofus <ARGS extends any[]> (f: (...args: ARGS) => any ) {}

goofus((a: string) => ({ dog() { return a; } }));
goofus((a: string) => ({ dog: function() { return a; } }));

Expected behavior:
infers ARGS === [string]

Actual behavior:
[ts] Argument of type '(a: string) => { dog(): string; }' is not assignable to parameter of type '() => any'.

Note that everything works correctly if you do any of the below:

  1. infer a single argument: function gallant <ARG extends any> (f: (arg: ARG) => any ) {}
  2. use arrow syntax in the object literal: goofus((a: string) => ({ dog: () => a }));
  3. use method syntax to return the object literal: goofus(function (a: string) { return { dog() { return a; } } });

Playground Link: link

Related Issues: couldn't find any

@ghost ghost added the Bug A bug in TypeScript label Aug 23, 2018
@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Aug 24, 2018

@ahejlsberg regression from 3.0 -> 3.1; I'm assuming your recent args work addresses this

@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.1 milestone Aug 24, 2018
@ahejlsberg
Copy link
Member

This is an issue caused by #25937. I'll have a fix up shortly.

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Aug 25, 2018
@billba
Copy link
Member Author

billba commented Aug 26, 2018

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants