DEV Community

Discussion on: We don't have to use Enums on TypeScript? 【Discussion】

Collapse
abhinav1217 profile image
Abhinav Kulshreshtha • Edited on

Real use case scenario of union types would be something like this

type StringOrNumber = string | number;
let code: StringOrNumber;
code = 123;   // OK
code = "ABC"; // OK
code = false; // Compiler Error
Enter fullscreen mode Exit fullscreen mode