-
> Obviously, this approach is even more inconvenient at the implementation side, but I find it more convenient on the consumer side. The implementer side complexity is less relevant if using codegen. `Symbol` is also skipped in `JSON.stringify` for both keys and values, so if you rely on it then it won't work and you'd need a branded primitive type if you care about nominal typing. I use schema-guided serialization so it's not an issue for me, but it's worth mentioning.
> Both the `as const` approach and my "class symbols" approach addresses [the complaints in this blog post about support variant annotations such `@deprecated`](https://blog.disintegrator.dev/posts/ode-to-typescript-enums...)). My class symbols approach gives you the flexibility to have different annotations for values and types; but I'm not sure how relevant it is. (It can also be achieved with `as const`, what matters for this is the type namespace declaration).
> I hope this message helps others when evaluating available solutions when migrating away from TS `enum`s.
[0]: https://github.com/microsoft/TypeScript/pull/61011#issuecomm...
-
InfluxDB
InfluxDB high-performance time series database. Collect, organize, and act on massive volumes of high-resolution data to power real-time intelligent systems.
-
Given the TypeScript team's stance on new non-erasable syntax, I have to think this is how they would have gone if they had `as const` from the beginning. Ron Buckton of the TS team is championing an enum proposal for JS: https://github.com/rbuckton/proposal-enum Hopefully that goes somewhere and improves the declaration side of thigns too.
-
When I see this it makes me want to run for ReasonML/ReScript/Elm/PureScript.
Sum types (without payloads on the instances they are effectively enums) should not require a evening filling ceremonial dance event to define.
https://reasonml.github.io/
https://rescript-lang.org/
https://elm-lang.org/
https://www.purescript.org/
(any I forgot?)
It's nice that TS is a strict super set of JS... But that's about the only reason TS is nice. Apart from that the "being a strict super set" hampers TS is a million and one ways.
To my JS is too broken to fix with a strict super set.
-
rescript
ReScript is a robustly typed language that compiles to efficient and human-readable JavaScript.
When I see this it makes me want to run for ReasonML/ReScript/Elm/PureScript.
Sum types (without payloads on the instances they are effectively enums) should not require a evening filling ceremonial dance event to define.
https://reasonml.github.io/
https://rescript-lang.org/
https://elm-lang.org/
https://www.purescript.org/
(any I forgot?)
It's nice that TS is a strict super set of JS... But that's about the only reason TS is nice. Apart from that the "being a strict super set" hampers TS is a million and one ways.
To my JS is too broken to fix with a strict super set.
-
When I see this it makes me want to run for ReasonML/ReScript/Elm/PureScript.
Sum types (without payloads on the instances they are effectively enums) should not require a evening filling ceremonial dance event to define.
https://reasonml.github.io/
https://rescript-lang.org/
https://elm-lang.org/
https://www.purescript.org/
(any I forgot?)
It's nice that TS is a strict super set of JS... But that's about the only reason TS is nice. Apart from that the "being a strict super set" hampers TS is a million and one ways.
To my JS is too broken to fix with a strict super set.
-
When I see this it makes me want to run for ReasonML/ReScript/Elm/PureScript.
Sum types (without payloads on the instances they are effectively enums) should not require a evening filling ceremonial dance event to define.
https://reasonml.github.io/
https://rescript-lang.org/
https://elm-lang.org/
https://www.purescript.org/
(any I forgot?)
It's nice that TS is a strict super set of JS... But that's about the only reason TS is nice. Apart from that the "being a strict super set" hampers TS is a million and one ways.
To my JS is too broken to fix with a strict super set.
-
Civet (https://civet.dev) is probably my favorite one if I want something a bit fancier than Typescript, purely because it shares the same elements that you are as "opt-in" as much as you like, at least in my limited experience.
-
CodeRabbit
CodeRabbit: AI Code Reviews for Developers. Revolutionize your code reviews with AI. CodeRabbit offers PR summaries, code walkthroughs, 1-click suggestions, and AST-based analysis. Boost productivity and code quality across all major languages with each PR.