Created
September 6, 2019 07:05
-
-
Save AhsanAyaz/a491d35e589639e1779824f08b8909a3 to your computer and use it in GitHub Desktop.
Discriminated Unions in Typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum CarTransmission { | |
Automatic = 200, | |
Manual = 300 | |
} | |
interface IMotorcycle { | |
vType: "motorcycle"; // discriminant | |
make: number; // year | |
} | |
interface ICar { | |
vType: "car"; // discriminant | |
transmission: CarTransmission | |
} | |
interface ITruck { | |
vType: "truck"; // discriminant | |
capacity: number; // in tons | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment