This is not really a TypeScript question but a JavaScript question.
Optional parameters must be at the back and can only be left out if all later arguments are left out as well. Otherwise JavaScript doesn't know for which parameter you passed a value.
Consider the second parameter in your example is optional. In a call you would just leave it out and not pass a value.
function addressCombo(street1, street2, street3) {}
addressCombo("LA", "LO")
However JavaScript doesn't know that you intended "LO"
to be the argument for street3
and not street2
. Instead it will assign them in the row.
In other words, you can't have an argument for street3
after you left out street2
.
What you could to is explicitly pass undefined
to the optional parameters, which is what would happen anyway if you left an argument out. In your example this would be
addressCombo("LA", undefined, "LO")
Please see also
Skip arguments in a JavaScript function
javascript: optional first argument in function
How to pass optional parameters while omitting some other optional parameters?