Closed
Description
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:
- infer a single argument:
function gallant <ARG extends any> (f: (arg: ARG) => any ) {}
- use arrow syntax in the object literal:
goofus((a: string) => ({ dog: () => a }));
- 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