InterviewSolution
Saved Bookmarks
| 1. |
What are template literal types? |
|
Answer» Template literal types are similar to the string literal types. You can combine them with concrete, literal types to produce a new string literal type. Template literal types allow us to use the string literal types as BUILDING blocks to create new string literal types. type Point = "GraphPoint";// type Shape = "Grid GraphPoint"type Shape = `Grid ${Point}`;Template literal types can also expand into multiple STRINGS via unions. It helps us create the SET of every POSSIBLE string literal that each union member can represent. type Color = "green" | "yellow";type Quantity = "five" | "SIX";// type ItemTwo = "five item" | "six item" | "green item" | "yellow item"type ItemOne = `${Quantity | Color} item`; |
|