typescript function and method 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: simple function in typescript

// Named function

//function with type as number
function add(x: number, y: number): number {
  // return sum of numbers entered as params
  return x + y;
}

// Anonymous function

// variable to call and define function
let myAdd = function (x: number, y: number): number {
  // return sum of numbers entered as params
  return x + y;
};