Skip to content

Improve tooltip for generic rest arguments in TypeScript #29514

@ghost

Description

I'm not sure if this should be a feature request or a bug report.

The Issue

Here is a code sample the illustrates the issue (you will have to read this to understand the rest of the post):

// the outer function `fun` accepts a callback function
// the callback function accepts a set of generic parameters
// the outer function `fun` returns a function that accepts the same parameters as the callback
function fun<A extends any[]>(cb: (...args: A) => any) {
  return (...args: A) => {};
}

// create a callback function to pass to `fun`
function callback(foo: string, bar: number) { }

// call `fun` and pass in `callback` 
// The value returned by `fun` will be a function that accepts the same parameters as `callback`.
// myVar will be of type: (foo: string, bar: number) => void
const myVar = fun(callback); 

If you type in this code into VSCode and hover over myVar, you will see that everything works fine. The parameters are shown alongside their types:

image

However, if you try to call the function by typing myVar( , the tooltip doesn't provide the expected information:

What I would expect to see is:

myVar(foo: string, bar: number): void

What I actually see is:

myVar(...args: [string, number]): void

image

The primary issue with the way it's currently implemented is that you cannot see the parameter names when you are calling the function, instead you only see the parameter types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions