Skip to content

Inaccurate Intellisense / Suggestions with Function Overloads #51047

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

Open
no-stack-dub-sack opened this issue Oct 1, 2022 · 2 comments
Open
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@no-stack-dub-sack
Copy link

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version:
    Version: 1.69.1 (system setup)
    Commit: b06ae3b2d2dbfe28bca3134cc6be65935cdfea6a
    Date: 2022-07-12T08:21:24.514Z
    Electron: 18.3.5
    Chromium: 100.0.4896.160
    Node.js: 16.13.2
    V8: 10.0.139.17-electron.0
    OS: Windows_NT x64 10.0.19044

Steps to Reproduce:

  1. Go to this playground and/or create a new TypeScript file with the code snippet shared below
  2. After "c" on the last line, type , "i"
  3. Note the intellisense and suggestions

Apologies, there's probably a better title for this issue...

I thought this might be a better issue for Monaco, but their issue template said that if I could recreate the issue in VS Code to open the issue here. Maybe this should be a TS issue instead since its reproducible in the playground as well? However, the TypeScript seems to be working fine, it's just the intellisense that seems to be confused.

Take the following code:

function doSomething<Type extends object, Key extends keyof Type>(
  item: Type,
  ...keys: Key[]
): void;

function doSomething<Type extends object, Key extends keyof Type>(
  items: Type[],
  ...keys: Key[]
): void;

function doSomething<Type extends object, Key extends keyof Type>(
  itemOrItems: Type,
  ...keys: Key[]
) {
  // omitted for brevity
}

type Foo = {
  a: number;
  b: number;
  c: string;
};

const x = doSomething({ a: 1, b: 2, c: "" } as Foo, "a", "b", "c");
const y = doSomething([{ a: 1, b: 2, c: "" }] as Foo[], "a", "c");

When spreading arguments into the function corresponding with the second overload, the intellisense provides inaccurate suggestions and incorrectly infers ...keys as (keyof Foo[])[] when it should actually be (keyof Foo)[]:

image

Again, note that TypeScript is working as expected, and accepting any of the suggestions provided by the intellisense will result in a type error.

@mjbvz mjbvz transferred this issue from microsoft/vscode Oct 3, 2022
@mjbvz mjbvz removed their assignment Oct 3, 2022
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Help Wanted You can do this Experience Enhancement Noncontroversial enhancements labels Oct 4, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Oct 4, 2022
@RyanCavanaugh
Copy link
Member

There's some logic in place to find the "right" signature when querying string literal completions, but it doesn't account for prior string arguments. This might be fixable with some elbow grease.

@RyanCavanaugh RyanCavanaugh added the Domain: Completion Lists The issue relates to showing completion lists in an editor label Oct 4, 2022
@no-stack-dub-sack
Copy link
Author

@RyanCavanaugh Thanks! Just wanted to add that while the completion list is affected by this, it does not seem isolated to the completion list. The type in any intellisense hover seems incorrect, regardless of whether its the first or Nth string argument provided.

image
keys is incorrectly typed in the overload hover 👆

image
keys is incorrectly typed in the problem hover 👆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants