1interface Safer_Easy_Fix {
2 title: string;
3 callback: () => void;
4}
5interface Alternate_Syntax_4_Safer_Easy_Fix {
6 title: string;
7 callback(): void;
8}
9
1function createPerson(name: string, doAction: () => void): void {
2 console.log(`Hi, my name is ${name}.`);
3 doAction(); // doAction as a function parameter.
4}
5
6// Hi, my name is Bob.
7// performs doAction which is waveHands function.
8createPerson('Bob', waveHands());
1// Named function
2
3//function with type as number
4function add(x: number, y: number): number {
5 // return sum of numbers entered as params
6 return x + y;
7}
8
9// Anonymous function
10
11// variable to call and define function
12let myAdd = function (x: number, y: number): number {
13 // return sum of numbers entered as params
14 return x + y;
15};
1// Named function
2function add(x: number, y: number): number {
3 return x + y;
4}
5
6// Anonymous function
7let myAdd = function (x: number, y: number): number {
8 return x + y;
9};