Skip to content

Use declared type parameters in signature help #15412

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

Closed
mjbvz opened this issue Apr 27, 2017 · 5 comments
Closed

Use declared type parameters in signature help #15412

mjbvz opened this issue Apr 27, 2017 · 5 comments
Labels
Bug A bug in TypeScript VS Code Tracked There is a VS Code equivalent to this issue

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Apr 27, 2017

From: microsoft/vscode#25363

TypeScript Version: 2.3.1

Code

type Z = { abc: number, xyz: string }

function foo<T>(z: keyof T) { }

foo<Z>('')

Trigger suggestions inside of the quotes in the function call.

Expected behavior:
Returns suggestions for abc and xyz

Actual behavior:
No suggestions returned in this case.

If a non-generic type is used:

type Z = { abc: number, xyz: string }

function foo(z: keyof Z) { }

foo('')

Then suggestions are returned

@mjbvz mjbvz added the VS Code Tracked There is a VS Code equivalent to this issue label Apr 27, 2017
@mhegazy mhegazy added the Bug A bug in TypeScript label Apr 27, 2017
@mhegazy mhegazy assigned ghost Apr 27, 2017
@mhegazy mhegazy added this to the TypeScript 2.4 milestone Apr 27, 2017
@ghost
Copy link

ghost commented May 12, 2017

The real problem is that we don't use a declared type parameter when getting signature help.

declare function f<T>(x: T): void;
f<number>(

Signature help here still shows f<T>(x: T): void.

@ghost ghost changed the title No Argument Suggestions Returned When Using keyof on Generic Type Use declared type parameters in signature help May 12, 2017
@ghost ghost closed this as completed in #16535 Jun 27, 2017
@dkirchhof
Copy link

I don't know, if it fits exactly to this problem, but i'm struggling with the autocompletion while using keyof.
Small example:

function keyofTest<Type>(context: Type, key: keyof Type)
{
	return context;
}

class Test
{
	a: string;
	b: number;
}

keyofTest<Test>(new Test(), "a") // this works as expected
keyofTest(new Test(), "") // this not really

The second function call shows me all possible types, while the cursor is before the comma, but not between the quotes anymore. A wrong key would also be marked. Two images attached to see the behaviour:

intellisense1
intellisense2

@ghost
Copy link

ghost commented Dec 19, 2017

@dkirchhof In the second case type inference has failed, since we can't infer any type Type such that new Test() : Type and "" : keyof Type. All parameters are used for type inference, not just the first. In this case you really only need the first, but it would be hard to change type inference to know about that, so instead it infers from all parameters and fails.

@dkirchhof
Copy link

Sorry, but i don't get it. At first, it shows me all possible keys (key: "a" | "b"), then it can't infer the type anymore and if a type in "c" or something else, which isn't a key of Test, it will be marked as a wrong argument until i change it to "a" or "b". So it just don't work for the "suggestions popup"?!

@ghost
Copy link

ghost commented Dec 21, 2017

It works in the compiler layer but that information doesn't get to services which provides the completions. I've made an issue #20843.

@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet
Development

No branches or pull requests

3 participants