function definition typescript code example

Example 1: types function typescript

interface Safer_Easy_Fix {
    title: string;
    callback: () => void;
}
interface Alternate_Syntax_4_Safer_Easy_Fix {
    title: string;
    callback(): void;
}

Example 2: typescript default parameter

function sayName({ first, last = 'Smith' }: {first: string; last?: string }): void {
  const name = first + ' ' + last;
  console.log(name);
}

sayName({ first: 'Bob' });

Example 3: types function typescript

interface Easy_Fix_Solution {
    title: string;
    callback: Function;
}

Example 4: typescript annotate return type

function add(x: number, y: number): number {
  return x + y;
}