Skip to content

Proposal: Passing Arguments by Name #5857

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
bryanerayner opened this issue Dec 1, 2015 · 2 comments
Closed

Proposal: Passing Arguments by Name #5857

bryanerayner opened this issue Dec 1, 2015 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@bryanerayner
Copy link

When a function has multiple optional arguments, callers of the function must use undefined to get the default, optional value.

Proposal

Add a syntax allowing function arguments to be passed by name. Unless there is a better suggestion, I propose the use of :=. This would be sugar, and rewrite the call site to invoke the function properly. A syntax error would be thrown if the argument name was not a specified parameter.

argumentName := value

Example syntax:

function func(a, b=2, c=3)
{
// Do work
}

// Proposed syntax
func(c:=4, a:=1);
// Results in the following javascript being output:
func(1, void 0, 4);

// Syntax error - Multiple specifications for argument 'a'
func(1, a:=1);

// Syntax error - 'd' is not a function parameter
func(1, d:=4);

// Valid syntax
func(a:=1);
// Rewrites to
func(1);
@kitsonk
Copy link
Contributor

kitsonk commented Dec 1, 2015

Personal opinion... it is anti-TypeScript design goals:

  1. Avoid adding expression-level syntax.

Non-goal:

  1. Exactly mimic the design of existing languages. Instead, use the behavior of JavaScript and the intentions of program authors as a guide for what makes the most sense in the language.

Object destructuring in ES6 with the combination of the terse object literal declarations in ES6 (both downward emittable) are more than sufficient to cover this type of functionality. TypeScript isn't trying to be a new language, it is trying to be a superset of JavaScript. This sounds a lot like a new language.

@mhegazy
Copy link
Contributor

mhegazy commented Dec 1, 2015

looks like a duplicate of #467

@mhegazy mhegazy closed this as completed Dec 1, 2015
@mhegazy mhegazy added the Duplicate An existing issue was already created label Dec 1, 2015
@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants