by sk0g · 3y ago · 0 comments
I know it all gets compiled away in JS and all, but Pydantic is surprisingly ergonomic to use and type hints are sort of a suggestion, albeit available at runtime.
Closest I've seen is Zod, but the syntax looks horrendous IMO. Maybe you look past it eventually though.
The casting doesn't guarantee the JSON from your server fits the interface, but it WILL ensure any downstream use is correct, and also enable auto complete for its fields (assuming your IDE supports it).
I've been using JavaScript on and off for nearly 20 years, and TypeScript is a massive improvement.
I have made such a library myself: https://github.com/decoverto/decoverto
Another library would be https://github.com/typestack/class-transformer