Skip to content

Autocomplete breaks in overloaded generic function #47081

@colinhacks

Description

@colinhacks

Bug Report

Autocomplete doesn't work in an overloaded generic function.

🔎 Search Terms

autocomplete vscode overload generic

🕗 Version & Regression Information

This is the behavior in every version I tried (4.1+ and nightly), and I reviewed the FAQ for entries about this.

⏯ Playground Link

Playground link with relevant code

💻 Code

type Shape = { foo: boolean };

function blarg<T>(shape: Shape): any;
function blarg<T>(shape: () => Shape): any;
function blarg(arg: any) {
  return arg;
}

blarg({ foo:true }); // autocomplete works here
blarg(() => ({ foo:true })); // but not here

Note that both functions are generic. This behavior occurs even though the generic parameter is unused. After removing the generic, autocomplete works fine for both overloads.

🙁 Actual behavior

In the first call to blarg (which uses the overload that expects an object), when you start typing f-o-o, the key name foo will be autosuggested.

In the second call to blarg (which uses the overload that expects an object-returning function), foo doesn't autocomplete when you start typing it.

If that found autocompletion only works on the first overload, in order of how the overloads are defined. In the playground, if you reverse the order of the two overloads, you will see the behavior switch.

🙂 Expected behavior

Autocompletion should work in all overloads.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Completion ListsThe issue relates to showing completion lists in an editor

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions