Skip to content

Parameters hints tooltip do not spread inferred arguments (inferred arguments names not visible). #28127

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
guillaume86 opened this issue Oct 25, 2018 · 3 comments
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript

Comments

@guillaume86
Copy link

TypeScript Version: typescript@3.2.0-dev.20181025

Search Terms:

  • spread infer arguments
  • infer argument name
  • ArgumentType

Code

type Fn = (...args: any[]) => any;
type ArgumentTypes<T extends Fn> = T extends (...args: infer U) => any ? U : never;

function buildActionCreator<
  T extends string,
  P extends (...args: any[]) => any
>(type: T, payloadCreator?: P) {
    return (...args: ArgumentTypes<P>) => {
        const payload = payloadCreator(...args) as ReturnType<P>;
        return {
            type,
            payload,
        };
    };
};

// if you hover here on setAge, the inferred arguments
// are spreaded and their names preserved: (age: number) => { ... }
const setAge = buildActionCreator("SET_AGE", (age: number) => ({ age }));

// the toolip showing function signatures when typing the open parenthesis
// do not spread arguments, the arguments names are lost: (...args: [number]) => { ... }  
// note that the hover on function tooltip still works ok
setAge(10);

Expected behavior:

When typing the opening parenthesis of setAge(, the tooltip showing function overloads should spread the inferred arguments and show the argument names like (age: number) => { ... }.

Actual behavior:

When typing the opening parenthesis of setAge(, the tooltip showing function overloads do not spread the inferred arguments and so the argument names are not visible (...args: [number]) => { ... }.

Playground Link:
http://www.typescriptlang.org/play/#src=type%20Fn%20%3D%20(...args%3A%20any%5B%5D)%20%3D%3E%20any%3B%0D%0Atype%20ArgumentTypes%3CT%20extends%20Fn%3E%20%3D%20T%20extends%20(...args%3A%20infer%20U)%20%3D%3E%20any%20%3F%20U%20%3A%20never%3B%0D%0A%0D%0Afunction%20buildActionCreator%3C%0D%0A%20%20T%20extends%20string%2C%0D%0A%20%20P%20extends%20(...args%3A%20any%5B%5D)%20%3D%3E%20any%0D%0A%3E(type%3A%20T%2C%20payloadCreator%3F%3A%20P)%20%7B%0D%0A%20%20%20%20return%20(...args%3A%20ArgumentTypes%3CP%3E)%20%3D%3E%20%7B%0D%0A%20%20%20%20%20%20%20%20const%20payload%20%3D%20payloadCreator(...args)%20as%20ReturnType%3CP%3E%3B%0D%0A%20%20%20%20%20%20%20%20return%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20type%2C%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20payload%2C%0D%0A%20%20%20%20%20%20%20%20%7D%3B%0D%0A%20%20%20%20%7D%3B%0D%0A%7D%3B%0D%0A%0D%0A%2F%2F%20if%20you%20hover%20here%20on%20setAge%2C%20the%20inferred%20arguments%0D%0A%2F%2F%20are%20spreaded%20and%20their%20names%20preserved%3A%20(age%3A%20number)%20%3D%3E%20%7B%20...%20%7D%0D%0Aconst%20setAge%20%3D%20buildActionCreator(%22SET_AGE%22%2C%20(age%3A%20number)%20%3D%3E%20(%7B%20age%20%7D))%3B%0D%0A%0D%0A%2F%2F%20the%20toolip%20showing%20function%20signatures%20when%20typing%20the%20open%20parenthesis%0D%0A%2F%2F%20do%20not%20spread%20arguments%2C%20the%20arguments%20names%20are%20lost%3A%20(...args%3A%20%5Bnumber%5D)%20%3D%3E%20%7B%20...%20%7D%20%20%0D%0A%2F%2F%20note%20that%20the%20hover%20on%20function%20tooltip%20still%20works%20ok%0D%0AsetAge(10)%3B

Related Issues:

@weswigham weswigham added the Experience Enhancement Noncontroversial enhancements label Oct 25, 2018
@AlexGalays
Copy link

Just hit this issue as well. It's not uncommon to just map the return type of a function while leaving the arguments untouched.

@dragomirtitian
Copy link
Contributor

This seems like a duplicate of #26563

@guillaume86
Copy link
Author

Thanks seems like it is, should close and mark as duplicate. I'll go upvote that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants