Skip to content

Instantly share code, notes, and snippets.

@AhsanAyaz
Created September 6, 2019 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AhsanAyaz/a491d35e589639e1779824f08b8909a3 to your computer and use it in GitHub Desktop.
Save AhsanAyaz/a491d35e589639e1779824f08b8909a3 to your computer and use it in GitHub Desktop.
Discriminated Unions in Typescript
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