November 2018
Beginner
502 pages
10h 22m
English
The discriminated union pattern allows us to handle the logic for different union types.
Let's go through an example:
interface ITextbox { control: "Textbox"; value: string; multiline: boolean;}interface IDatePicker { control: "DatePicker"; value: Date;}interface INumberSlider { control: "NumberSlider"; value: number;}
They all have a property called control, which will be the discriminant in the pattern.
type Field = ITextbox | IDatePicker | INumberSlider;
So, we can create union types from any types, and not just string literals. In this ...
Read now
Unlock full access