TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Intellisense chooses schema so fast

Open wizard8912 opened this issue 2 years ago • 3 comments

TS Template added by @mjbvz

TypeScript Version: 5.0.1-rc

Search Terms


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

  • VS Code Version: 1.72.2
  • OS Version: Windows10

Steps to Reproduce:

  1. Declare below code:
declare class MyClass {
	addObject(config: {
		type: "Triangle",
		base: number,
	});

	addObject(config: {
		type: "Circle",
		diameter: number,
	});
}

const myClass = new MyClass();
  1. Now when you want to use addObject method and check possible options for type all works well, like below: image

  2. Make parameters base and diameter as optional, so declare below code:

declare class MyClass {
	addObject(config: {
		type: "Triangle",
		base?: number,
	});

	addObject(config: {
		type: "Circle",
		diameter?: number,
	});
}

const myClass = new MyClass();

Now, until I write type parameter, all works well, because I see, that possible values for type are Triangle and Circle: image

but after writing type, Intellisense decided to chose first option, and I don't see another possible values to choose, although they have correct schema still and could be possible to select also: image

wizard8912 avatar Mar 16 '23 08:03 wizard8912

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.76.2. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

vscodenpa avatar Mar 16 '23 08:03 vscodenpa

can confirm the aforementioned behavior

image but if you add double quote then ctrl+space the suggestion comes back correctly

valen214 avatar Mar 16 '23 14:03 valen214

An omitted expression like this is replaced with any so the overload selection mechanism essentially checks if the provided argument with type { type: any } is assignable to the param with type { type: "Triangle"; base?: number | undefined; }. This succeeds so the first overload gets selected.

Fixing this might require some effort/a different approach to how completions are provided in cases like this. Note that, for example, getStringLiteralCompletionsFromSignature is already using a different - overload-capable~ - strategy to provide completion directly at argument positions. This one is nested in the argument and thus a simpler approach of getContextualType is used here.

Andarist avatar Jun 26 '23 14:06 Andarist