typehero typescript challenge Day one - Christmas Cookies - Advent of TypeScript
Series
Advent of TypeScript Solutions
Episode 1 • Season 1

Day 1 | Christmas Cookies | Typehero Advent of TypeScript Challenge

171Reads
2 December, 2023

Explanation:-

In this challenge, you are asked to define a TypeScript type named SantasFavoriteCookies. Santa has two favorite cookie flavors this year: "ginger-bread" and "chocolate-chip". Your task is to create a type that allows only these two specific string values.

In TypeScript, you can create such a type using a union of string literal types. This means that SantasFavoriteCookies should be a type that can only be either 'ginger-bread' or 'chocolate-chip'.

Here's the simple code to complete this task:

type SantasFavoriteCookies = 'ginger-bread' | 'chocolate-chip';

By defining SantasFavoriteCookies in this way, you ensure that this type can only be one of these two specific strings, exactly as Santa's cookie preferences are described.

Link to Day one Challenge on TypeHero.dev:- https://typehero.dev/challenge/day-1

That's it! See you in the next Day 2 Challenge.