Skip to content

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

Closed
@billba

Description

@billba

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions