05.TypeScript_타입별칭(type alias)

이동훈·2022년 5월 9일

typescript

목록 보기
3/3

Type 키워드로 타입 별칭 만들기

type 타입 키워드는 기존에 존재하는 타입을 단순히 이름만 바꿔서 사용할 수 있게 해줍니다. 이러한 기능을 타입 별칭(type alias) 이라고 합니다.

type 새로운 타입 = 기존 타입
<<type-alias.ts>>
  
type stringNumberFunc = (string, number) => void;
let f: stringNumberFunc = function (a: string, b: number): void {};
let g: stringNumberFunc = function (c: string, d: number): void {};

실습

함수의 타입, 즉 함수 시그니처를 명시하면 위에 실습처럼 매개변수의 개수나 타입, 반환타입이 다른 함수를 선언하는 잘못을 미연에 방지할 수 있습니다.

profile
한계를 부시는 프론트개발자

0개의 댓글