1// Optional Parameters
2sayHello(hello?: string) {
3 console.log(hello);
4}
5
6sayHello(); // Prints 'undefined'
7
8sayHello('world'); // Prints 'world'
1// Optional parameter
2function foo(x?: number) {
3 console.log("x : "+ x);
4}
5foo();
6foo(6);
1
2
3
4
5 function multiply(a: number, b: number, c?: number): number {
6
7 if (typeof c !== 'undefined') {
8 return a * b * c;
9 }
10 return a * b;
11}
1// Optional type parameters
2private logData<T, S = {}>(operation: string, responseData: T, requestData?: S) {
3 // your implementation here
4}
5