const 함수 = (a : string) : string => {
return a;
}
보통 함수에 타입을 지정할때, 파라미터와 함수 리턴값에 각각 타입을 지정해주는데,
함수 자체에 타입을 지정해줄 수 있다.
type FuncType = (a : string) => number; // 리턴값이 없을 경우 {} 생략 가능
const 함수 :FuncType = (a) => {
return 10;
}
함수에 type alias 를 지정해주고 그 타입을 사용하려면 함수 표현식으로 작성해주어야한다.
type CutZeroType = (a: string) => string;
type RemoveDashType = (a: string) => number;
const cutZero: CutZeroType = (a) => {
return a;
};
const removeDash: RemoveDashType = (a) => {
return 10;
};
cutZero('a');
removeDash('c');