Skip to content

Improved argument description for parameters originating from tuples #30084

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

Merged
merged 3 commits into from
Mar 18, 2019

Conversation

dragomirtitian
Copy link
Contributor

@dragomirtitian dragomirtitian commented Feb 25, 2019

Improved argument description for parameters originating from tuples that were extracted from functions. (ie mapped functions).

If the function parameters come from a tuple extracted from function parameters, then the signature help now provides the same information as the quick info. This means that if the tuple was extracted from a function we will now have the same names for the parameters as in the original function.

Ex:

function fnTest(str: string, num: number) { }
declare function wrap<A extends any[], R>(fn: (...a: A) => R) : (...a: A) => R;
var fnWrapped = wrap(fnTest);
fnTest(/*1*/) // At 1 - fnWrapped(str: string, num: number): void instead of function fnTest(...a: [string, number]) : void

Implementation notes:

  1. I added getExpandedParameters to TypeChecker but marked it as internal so as not to impact the public API. This function might however be useful for clients of the API. Let me know if I should remove the internal.

  2. If the argument of the mapped function is a single rest parameter the name of the parameter is not preserved in the quick info. Since this fix uses the same function as quick info (getExpandedParameters) it will suffer from the same issue.

function fnTestVariadic (...num: number[]) { }
var fnVariadicWrapped = wrap(fnTestVariadic);
fnVariadicWrapped() // fnVariadicWrapped(...a: number[]): void instead of fnVariadicWrapped(...num: number[]): void

This seems to be caused by the fact that the signature parameters will just have the rest parameter (...a: num[]) not a tuple with the rest (...a: [...number[]]).

This could be the topic of a different issue.

  1. If the parameters do not originate from a function (ex: function fnTest3(...a: [number, string]) { }) the quick info shows a signature with the tuple spread to several parameters and an index added (function fnTest3(a_0: number, a_1: string): void ) this will also now be shown by the signature help as well. While this does not seem like a great improvement at least it is consistent.

Fixes #26563, #28127, #29514

…that were extracted from functions. (ie mapped functions)
@dragomirtitian
Copy link
Contributor Author

On a personal note, this issue has been bugging me since 3.0, hope it gets merged :)

@dragomirtitian
Copy link
Contributor Author

@RyanCavanaugh Is there anything blocking this PR and anything I can do to move it along? Or is it just a matter of time and priorities and someone will get to it when they get to it :) ?

@ahejlsberg
Copy link
Member

@dragomirtitian Added a few comments in the code. If you update the PR we'll get it merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better argument description for inferred argument types
2 participants