function sayName(params: {firstName: string; lastName?: string}) {
params.lastName = params.lastName || 'smith'; // <<-- any better alternative to this?
var name = params.firstName + params.lastName
alert(name);
}
sayName({firstName: 'bob'});
I had imagined something like this might work:
function sayName(params: {firstName: string; lastName: string = 'smith'}) {
Obviously if these were plain arguments you could do it with:
function sayName(firstName: string, lastName="smith") {
var name = firstName + lastName;
alert(name);
}
sayName('bob');
And in coffeescript you have access to the conditional existence operator so can do:
param.lastName ?= 'smith'
Which compiles to the javascript:
if (param.lastName == null) {
param.lastName="smith";
}