What are Discriminated union types?
In TypeScript, a discriminated union type is also called “tagged union types” or “algebraic data types”. It is a type that represents a value that can be one of several different types, with a tag indicating the type of the value. To create a discriminated union type in TypeScript, use the ‘|’ operator to combine the set of types. Here, the “discriminant” property can be used to distinguish between the different shapes of the object.
A discriminated union…