how to typescript a function argument code example
Example 1: typescript default parameter
sayHello(hello: string = 'hello') {
console.log(hello);
}
sayHello();
sayHello('world');
Example 2: typescript function as parameter
function createPerson(name: string, doAction: () => void): void {
console.log(`Hi, my name is ${name}.`);
doAction();
}
createPerson('Bob', waveHands());
Example 3: typescript function type
function sayHello(name: string): string {
console.log(`Hello, ${name}`!);
}
sayHello('Bob');
Example 4: types function typescript
interface Easy_Fix_Solution {
title: string;
callback: Function;
}