Reputation:
How can I make a Typescript function parameter have a default value ?
I have this code:
modalSubmit = (autoSave) => {
var self = this;
self.stateService.network('Submitting');
self.modal.resetDisabled = true;
self.modal.submitDisabled = true;
autoSave = autoSave || false;
Is there a way with Typescript that I can make autoSave default to false if it's not set ?
Upvotes: 2
Views: 160
Reputation: 275927
Just for information, if you are wondering how you should check for a value in pure JS:
autoSave = autoSave !== undefined ? autoSave : false;
Of course typescript does it for you.
Upvotes: 0
Reputation: 26406
yep: http://www.codebelt.com/typescript/javascript-default-parameters-with-typescript-tutorial/
modalSubmit = (autoSave: boolean = false) => {
...
}
Upvotes: 5