[[Template literal type]]을 잘 활용하면 패턴을 갖고 있는 타입을 쉽게 만들 수 있다. 예를 들면, ```typescript type Top = "t-shirt" | "shirts" | "jacket"; type Bottom = "jeans" | "skirt" | "slacks"; type Outfit = `${Top} with ${Bottom}`; //expected: "t-shirt with jeans" //| "t-shirt with skirt" //| "t-shirt with slacks" //| "shirts with jeans" //| "shirts with skirt" //| "shirts with slacks" //| "jacket with jeans" //| "jacket with skirt" //| "jacket with slacks" ``` 기존에 존재했던 `Top`, `Bottom` 타입을 가지고 `Outfit` 이라는 새로운 타입을 만들 수 있는데 `Top`, `Bottom` 의 조합으로 총 9개의 string union type을 만들 수 있다. --- 좀 더 실용적인 예제를 보여주면 `user`, `post`, `comment` 가 같은 패턴의 이름을 갖고 있을 때 번거롭게 `interface` 선언할 것이 아니라 [[Template literal type]]을 활용하면 아래와 같이 쉽게 타입을 생성할 수 있다. ```typescript type TemplateLiteralKey = `${"user" | "post" | "comment"}${"Id" | "Name"}`; type ObjectOfKeys = Record<TemplateLiteralKey, string>; //expected: //{ // userId: string; // userName: string; // postId: string; // postName: string; // commentId: string; // commentName: string; //} ``` --- 참조 강의: https://inf.run/FVDi