Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

template literal types

/** A template literal produces a new string literal type by concatenating
    the contents. When a union is used in the interpolated position, the 
    type is the set of every possible string literal that could be 
    represented by each union member: */

type Taste = "Delicious" | "Spicy";
type Food = "Pizza" | "Meat";
 
type Menu = `${Taste | Food}`;

// Menu will now be one of the following:
// 'DeliciousPizza' | 'DeliciousMeat' | 'SpicyPizza' | 'SpicyMeat'
Source by codeburst.io #
 
PREVIOUS NEXT
Tagged: #template #literal #types
ADD COMMENT
Topic
Name
7+8 =