type return type of a function typescript code example
Example 1: typescript default parameter
function sayName({ first, last = 'Smith' }: {first: string; last?: string }): void {
const name = first + ' ' + last;
console.log(name);
}
sayName({ first: 'Bob' });
Example 2: get function return type typescript
type return_type = ReturnType<() => string>; // string
// or
function hello_world(): string {
return "hello world";
}
type return_type = ReturnType<typeof hello_world>; // string