You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
functionfunc(a,b=2,c=3){// Do work}// Proposed syntaxfunc(c:=4,a:=1);// Results in the following javascript being output:func(1,void0,4);// Syntax error - Multiple specifications for argument 'a'func(1,a:=1);// Syntax error - 'd' is not a function parameterfunc(1,d:=4);// Valid syntaxfunc(a:=1);// Rewrites tofunc(1);
The text was updated successfully, but these errors were encountered:
Personal opinion... it is anti-TypeScript design goals:
Avoid adding expression-level syntax.
Non-goal:
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.
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:
The text was updated successfully, but these errors were encountered: