Skip to content

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

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
wyntau opened this issue Sep 19, 2016 · 5 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@wyntau
Copy link

wyntau commented Sep 19, 2016

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
}
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Sep 19, 2016
@kitsonk
Copy link
Contributor

kitsonk commented Sep 19, 2016

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

@RyanCavanaugh
Copy link
Member

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

@wyntau
Copy link
Author

wyntau commented Sep 20, 2016

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

@yortus
Copy link
Contributor

yortus commented Sep 20, 2016

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.

@RyanCavanaugh RyanCavanaugh added Declined The issue was declined as something which matches the TypeScript vision and removed In Discussion Not yet reached consensus labels Sep 28, 2016
@RyanCavanaugh
Copy link
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.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants