Re:Rewriting TypeScript in Rust? You'D have to be
by refulgentis on Wednesday December 14, 2022 @08:00PM
(#33993461)
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
[ Parent
| on HN ]
Re:Rewriting TypeScript in Rust? You'D have to be
by esprehn on Wednesday December 14, 2022 @09:18PM
(#33994231)
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
Re:Rewriting TypeScript in Rust? You'D have to be
by goto11 on Thursday December 15, 2022 @11:33AM
(#34001967)
"Some extra quotes" make a big difference though. The type of
Red
in OCaml is pretty unambiguous, but the type of "Red"
in Typescript is not. The typesystem has to do a lot of work to support strings as both enum values, type descriptors and characters-strings.
Re:Rewriting TypeScript in Rust? You'D have to be
by wruza on Thursday December 15, 2022 @04:37AM
(#33997211)
This doesn’t change anything:
foo(get_some_myenum_value(), …)
{type:get_another(), …}
These are as unguessable as if myenum was a string.
Re:Rewriting TypeScript in Rust? You'D have to be
by madeofpalk on Thursday December 15, 2022 @06:08AM
(#33997798)
Hmm. That doesn't feel like much of a difference to me?
Re:Rewriting TypeScript in Rust? You'D have to be
by refulgentis on Thursday December 15, 2022 @10:30AM
(#34001037)
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.