Skip to content

Files

Latest commit

 

History

History
22 lines (17 loc) · 490 Bytes

how-to-type-a-function-in-an-interface.md

File metadata and controls

22 lines (17 loc) · 490 Bytes

How to Type a Function in an Interface


In TypeScript you can type a function in two ways.

interface Bird {
  flapWings(flaps: number): number;
  sing: (song: string) => string;
}

let bird: Bird = {
  flapWings: function (flaps: number) {
    return flaps * 2
  },
  sing: (song: string) => `Chirp ${song} Chirp!`
}

example link