JavaScript Coder

typescript optional parameter or default value

Typescript Optional Parameters

All parameters of a function are required by default. The parameters of a function should match the type specified by the function signature as well. For Example: function fullName(first:string, middle:string, last:string) { return first+" "+middle+" "+last; } fullName("Mark");//Error parameters middle and last are missing fullName("Mark", null,null);//Error: null is not assignable to string fullName("Mark", undefined,undefined);//Error: undefined is not assignable to string Syntax for optional parameters Here is the code that declares middle and last names to be optional:

Continue Reading →