Skip to content

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

Closed

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

Activity

  1. ghost added
    BugA bug in TypeScript
    on Aug 23, 2018
  2. RyanCavanaugh commented on Aug 24, 2018

    @RyanCavanaugh
    Member

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

  3. ahejlsberg commented on Aug 25, 2018

    @ahejlsberg
    Member

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

  4. billba commented on Aug 26, 2018

    @billba
    MemberAuthor

    Thank you!

  5. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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