typescript funciton code example
Example 1: typescript function as parameter
function createPerson(name: string, doAction: () => void): void {
console.log(`Hi, my name is ${name}.`);
doAction();
}
createPerson('Bob', waveHands());
Example 2: typescript function type
function sayHello(name: string): string {
console.log(`Hello, ${name}`!);
}
sayHello('Bob');
Example 3: typescript function
function add(x: number, y: number): number {
return x + y;
}
let myAdd = function (x: number, y: number): number {
return x + y;
};
Example 4: types function typescript
interface Param {
title: string;
callback: function;
}