3 ms·
How do you express option/enum types without enums? And if you do that, isn't it more of an unsupported way of doing things than using the native enum type?
by FireInsight 3y ago
How do you express option/enum types without enums? And if you do that, isn't it more of an unsupported way of doing things than using the native enum type?
- jauco 3y agoI guess unions of string or number literals? type Option = “foo” | “bar"
- iainmerrick 3y agoYes, exactly this. For most purposes it's simpler and better than TS enums.
- dabber 3y agoconst assertions work well: https://devblogs.microsoft.com/typescript/announcing-typescript-3-4/#const-assertions https://devblogs.microsoft.com/typescript/announcing-typescr.... There is an example in the "Objects vs Enums" section of the Enum docs, at the bottom of the page: https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums https://www.typescriptlang.org/docs/handbook/enums.html#obje...