Hacker News new | past | comments | ask | show | jobs | submit login

Most model it as an actual enum, if backed by strings. Typescript, by comparison, requires being able to indicate a type just from a string argument



Allowing literal strings and type aliases of unions of strings to represent enums doesn't seem unreasonable. It's the same concept as many other languages with some extra quotes, ex. https://ocaml.org/docs/data-types#a-simple-custom-type


This doesn’t change anything:

  foo(get_some_myenum_value(), …)
  {type:get_another(), …}
These are as unguessable as if myenum was a string.


Hmm. That doesn't feel like much of a difference to me?


It's huge? I'm really confused lol. I write in Dart/Java/C++/ObjC/TS regularly to maintain a cross-platform library and this is a massive difference from every typechecker in any other language, much less the narrower thing of if the idea of reifying random strings into an enum is a novel feature. I get a very strong sense from the thread that people are talking past eachother, somehow.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: