Function Types

function add(x: number, y: number): number {
    return x + y
}
let myAdd = function(x: number, y: number): number {
    return x + y
}
let myAdd2: (x: number, y: number) => number
myAdd2 = myAdd
myAdd2(10, 20) // 30

Inferring the types

let myAdd: (baseValue: number, increment: number) => number = function(x, y) {
  return x + y
}
myAdd(10, 20) // 30

Optional Parameters

function buildName(first: String, last?: String): String {
  if (last) {
    return first + " " + last
  }
  return first
}
buildName("YOON") // YOON
buildName("YOON", "BYEONGIN") // YOON BYEONGIN

Default Parameter

function sayHi(yourName: String, greet = "Hi") {
  return greet + ", " + yourName
}
sayHi("yoon"); // Hi, YOON
sayHi("YOON", "HELLO"); // HELLO, YOON

Rest Parameters

function buildName(firstName: String, ...lastName: String[]): String {
  return firstName + " " + lastName.join(" ")
}
buildName("YOON", "BYEONGIN", "JJANG", "MAN!") // YOON BYEONGIN JJANG MAN!