←back to thread

203 points dahlia | 1 comments | | HN request time: 0.214s | source
Show context
parhamn ◴[] No.45153467[source]
> Try to access it and TypeScript yells at you. No runtime validation needed.

I was recently thinking about type safety and validation strategies are particularly thorny in languages where the typings are just annotations. E.g. the Typescript/Zod or Python/Pydantic universes. Especially in IO cases where the data doesn't originate in the same type system.

In a language like Go (just an example, not endorsing) if you parse something into say a struct you know worst case you're getting that struct with all the fields set to zero, and you just have to handle the zero values. In typescript-likes you can get a totally different structure and run into all sorts of errors.

All that is to say, the runtime validation is always somewhere (perhaps in the library, as they often are?), and the feature here isn't no runtime validation but typed cli arguments. Which is cool and great.

replies(1): >>45153829 #
metaltyphoon ◴[] No.45153829[source]
> worst case you're getting that struct with all the fields set to zero, and you just have to handle the zero values

In the field I work, zero values are valid and doing it in Go would be a nightmare

replies(2): >>45154434 #>>45158290 #
1. parhamn ◴[] No.45154434[source]
Agreed, the pointer or "<field>_empty: bool" patterns are annoying. Point still stands though, you always get the structure you ask for.