return type typescript function code example
Example 1: typescript function as parameter
function createPerson(name: string, doAction: () => void): void {
console.log(`Hi, my name is ${name}.`);
doAction(); // doAction as a function parameter.
}
// Hi, my name is Bob.
// performs doAction which is waveHands function.
createPerson('Bob', waveHands());
Example 2: typescript annotate return type
function add(x: number, y: number): number {
return x + y;
}