Re:Functions and algorithms implemented purely with TypeScri...
by edem on Wednesday July 05, 2023 @08:28AM
(#36599439)
I come from a Java / Kotlin background and TS is totally fine.
[ Parent
| on HN ]
Re:Functions and algorithms implemented purely with TypeScri...
by sk0g on Wednesday July 05, 2023 @08:53AM
(#36599725)
Some quirks I've noticed are typed objects not performing any validations, like for building DTOs. Structural typing so the newtype pattern is not possible without some awkward hacks. A general "disconnect" between compile time and run time behaviour, so once you start casting your errors are relegated to property access/usage time, which makes — IMO excessive — test coverage paramount in catching bugs wherever you have conditional logic.
I would have gone with C# or Kotlin if I had the luxury of choice, but I'll get that with a deliberate career move maybe.
Re:Functions and algorithms implemented purely with TypeScri...
by ncallaway on Wednesday July 05, 2023 @10:30AM
(#36600972)
If you’re taking in data from
an external source that needs to be validated, I highly recommend a schema library like zod, that can produce a typescript type.
That way you can define the type in a single place, have runtime validation for that type, but also be able to use the type in typescript at compile time.