1) 문장식
function addTwoNumbers(x: number, y: number){
return x + y;
}
2) 표현식
const addTwoNumbersExp = (x:number , y : number) => {
return x + y;
}
function add(x: number, y: number) : number{
return x+ y;
}
function subtract(x: number, y: number) : number{
return x+ y;
}
function multifly(x: number, y: number) : number{
return x+ y;
}
function divide(x: number, y: number) : number{
return x+ y;
}
보면 함수 선언할 때마다 타입을 선언해준다. 매우 번거로운 작업이다.
type CalculationType = (x:number, y:number) => number;
const add2 : CalculationType = function(x, y){
return x + y;
}
const subtract2 : CalculationType = function(x, y){
return x + y;
}
const multifly2 : CalculationType = function(x, y){
return x + y;
}
const divided2 : CalculationType = function(x, y){
return x + y;
}
표현식 함수의 시그니처 타입으로 선언한 다음에 반복적으로 해주는 것이 더 깔끔하다