Closed
Description
C# allows adding names of arguments in a function call:
CalculateBMI(weight: 123, height: 64);
See http://msdn.microsoft.com/en-us/library/dd264739.aspx
In TypeScript's source this is also done, but with comments:
emitLinesStartingAt(nodes, /*startIndex*/ 0);
Can we have named arguments in TypeScript like this:
emitLinesStartingAt(nodes, startIndex: 0);
This can add some compile time checking, for instance when you type count: 0
you will get an error.
I think we should add a restriction that the order of the arguments cannot be changed. Example:
function foo(first: number, second: number) {}
var z = 3;
foo(second: z++, first: z);
An error should be thrown on the last line, because changing the order of the arguments (to foo(z, z++)
) in the generated javascript would cause unexpected behavior.
Also this can be useful for functions with lots of optional arguments:
function foo(a?, b?, c?, d?, e?) {}
foo(e: 4);
foo(d: 8, 5); // e will be 5
Generates
function foo(a, b, c, d, e) {}
foo(void 0, void 0, void 0, void 0, 4);
foo(void 0, void 0, void 0, 8, 5);