Typescript has unions, so are enums redundant?
问题 Ever since TypeScript introduced unions types, I wonder if there is any reason to declare an enum type. Consider the following enum type declaration: enum X { A, B, C } var x:X = X.A; and a similar union type declaration: type X: "A" | "B" | "C" var x:X = "A"; If they basically serve the same purpose, and unions are more powerful and expressive, then why are enums necessary? 回答1: As far as I see they are not redundant, due to the very simple reason that union types are purely a compile time