microsoft / microsoft/TypeScript

Starting overload selection in signature help doesn't account for discriminating arguments

Open
#36,582 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Experience Enhancement Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TS Template added by @mjbvz

TypeScript Version: 3.8.0-dev.20200201

Search Terms

  • overload

Incorrect types sugestion with overload
https://gitlab.com/kamidere-laboratory/duat/tree/testy
overload is declarated in src/database/Controller.ts method create

  • VSCode Version: 1.41.1
  • OS Version: Windows_NT x64 10.0.18362

Steps to Reproduce:

  1. Write Database.create(DatabaseType.Graphite, {}) // now we get Influx overload xD
  2. Change DatabaseType.Graphite to DatabaseType.Sqlite // now we get Sqlite overload :D
  3. Change back to DatabaseType.Graphite // now we still get Sqlite overload :(
    https://youtu.be/a7FHxIItceA

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

image
image
image

interface a {
  a: string;
  b: string;
  c: {
    a:number;
    b:string;
  }
}

interface b {
  a: string;
  b: string;
  c: {
    a: number;
    b: string;
    c: string[];
  }
}

interface c {
  a: string;
  b: string;
}

enum d {
  "A" = 'a',
  "B" = 'b',
  "C" = 'c',
}

class testClass {
  constructor(arg1: d, arg2: a | b | c) {
    console.log(arg1, arg2)
  }
  static doSomething(arg1: d.A, arg2: a): testClass;
  static doSomething(arg1: d.B, arg2: b): testClass;
  static doSomething(arg1: d.C, arg2: c): testClass;
  static doSomething(arg1: d, arg2: a | b | c): testClass {
    return new this(arg1, arg2);
  }
}

testClass.doSomething(d.C, {});

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the overload example in the issue and inspect TypeScript's signature-help handling for overload selection. Verify the behavior when the discriminating first argument changes between enum values; done means signature help selects the overload matching that argument rather than retaining the previously selected overload.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.