Re:How porting to TypeScript solved our API woes
by tluyben2 on Thursday April 09, 2020 @12:25AM
(#22819766)
The OP mentioned this in the context of ‘why not a fully statically typed language’, aka a language that, unlike typescript, does not return hard-to-understand errors; given such a language, what is an example that falls in that 99-100% 1%? I do not know of such an example and I am curious.
[ Parent
| on HN ]
Re:How porting to TypeScript solved our API woes
by Aeolun on Thursday April 09, 2020 @03:39AM
(#22820558)
One example is that TS does not enjoy you going from string enum keys to an actually typed enum, but you can fake it by casting to ‘any’ first and then to the new type.
Re:How porting to TypeScript solved our API woes
by tluyben2 on Thursday April 09, 2020 @05:30AM
(#22821009)
Sorry, but that was not the question; the question was about examples on a statically typed language like Java (or Kotlin, C# etc), which is what the OP mentioned.
Statically typed languages do not 'enjoy' going from strings to enums, which is excellent news by the way, but you can convert them Enum.TryParse() to handle them properly. I cannot really see how it is 'more work' to do that; the 'any' solution seems not much easier compared to C# TryParse or even the TS one;
var color : Color = Color[green as keyof typeof Color];