Search⌘ K

Solution Review: Create Algebraic Data Type

Explore how to define algebraic data types in TypeScript by modeling example types like Car and Bicycle. Understand key syntax and concepts to apply functional programming more effectively using fp-ts in your projects.

We'll cover the following...

Solution

The code provided below is the solution to the Create Algebraic Data Type challenge:

TypeScript 3.3.4
type Car = {
mileage: number,
numberOfSeats: number,
};
type Bicycle = {
luggageRack: boolean,
};
type Vehicle = Car | Bicycle;

Explanation

Here is a ...