Skip to content

Suggestion: use :{type} to omit formal parameter when declare function interface or something else #10984

Closed

Description

@ik0r

When we declare a function interface, omit formal parameter. Because the param name is not important in interface, just the param type does.

So, we can make below code

interface func{
    (paramA: typeA, paramB: typeB): typeC;
}

to this form

interface func{
    (:typeA, :typeB): typeC
}

Activity

  1. kitsonk commented on Sep 19, 2016

    @kitsonk
    Contributor

    The formal parameter name is often useful for intellisense when using semantically meaningful parameter names, is it not?

  2. RyanCavanaugh commented on Sep 19, 2016

    @RyanCavanaugh
    Member

    I mean, you can't stop someone from not providing a useful name. p0, p1, p2, etc.

  3. ik0r commented on Sep 20, 2016

    @ik0r
    Author

    I mean, TypeScript can support this form but it's optional. So someone can omit the formal parameter name. Because sometime we don't know the correct parameter name until we implement it

  4. yortus commented on Sep 20, 2016

    @yortus
    Contributor

    There are situations like this where omitting some parameter names would be a small mercy. But that particular pattern will hopefully one day be addressed better by something like #5453.

    In general there are cases where the intent of declaring a function type is purely to describe a mapping from certain parameter type(s) to a certain return type, and giving names to the parameters is mostly meaningless boilerplate. You can see some of these in ramda.d.ts.

    Basically any situation where you'd be temped to name things arg1, arg2 and so on would be candidates for this proposal. The compiler would probably internally name them arg1, arg2 etc for intellisense anyway.

  5. added
    DeclinedThe issue was declined as something which matches the TypeScript vision
    and removed on Sep 28, 2016
  6. RyanCavanaugh commented on Sep 28, 2016

    @RyanCavanaugh
    Member

    We'd really like people to try hard to come up with parameter names, and this syntax looks really weird on its own (is it a weird kind of parameter name? a destructuring? something else?) so we'd prefer to keep names mandatory at this point.

  7. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions