creating a function in typescript code example
Example 1: typescript default parameter
sayHello(hello: string = 'hello') {
console.log(hello);
}
sayHello();
sayHello('world');
Example 2: types function typescript
interface Safer_Easy_Fix {
title: string;
callback: () => void;
}
interface Alternate_Syntax_4_Safer_Easy_Fix {
title: string;
callback(): void;
}
Example 3: typescript function as parameter
function createPerson(name: string, doAction: () => void): void {
console.log(`Hi, my name is ${name}.`);
doAction();
}
createPerson('Bob', waveHands());
Example 4: types function typescript
interface Param {
title: string;
callback: function;
}