[한입] 템플릿 리터럴 타입

TK·2023년 12월 18일
0

[강의] 한입 시리즈

목록 보기
51/59

템플릿 리터럴 타입

(Template Literal Type)

스트링 리터럴 타입을 기반으로 정해진 패턴의 문자열만 포함하는 타입

  • 다음과 같이 템플릿 리터럴 타입으로 원하는 형태의 조합을 작성한다.
type Color = "red" | "balck" | "green";

type Animal = "dog" | "cat" | "chicken";

type ColoredAnimal = `${Color}-${Animal}`; // 👈

const coloredAnimal: ColoredAnimal = "balck-cat";

  • 아래와 같이 모든 조합이 나타남
profile
쉬운게 좋은 FE개발자😺

0개의 댓글