Instead of doing the popular Advent of Code, this year I tried to complete the Advent of TypeScript. In this article, you'll find my solutions and some details on how they work or what I learned while solving the challenge.
What are we talking about?
In TypeScript, it is possible to define types in several ways: interface, class, enum, the
as const, and more. In this article, we will focus on types constructed from a discriminated union and the advantages of such a practice. In TypeScript, unions are created using the
| symbol (e.g.,
type Union = A | B | C). The term "disjoint" is not accidental because, unlike polymorphism, the types we will use may have nothing in common.