News for hackers. Stuff that matters.
Re:Designing the perfect TypeScript schema validation library by cjdell on Thursday March 12, 2020 @07:03PM (#22562955)
I built something like this a few months ago but struggled to explain to almost everyone except die hard TypeScript fans what the big deal was.

I explained it was all about the type inference from the schema so I could make guarantees across runtime boundaries.

This is what I came up with, though this library looks like it may be more comprehensive than what I wrote. Struggled to come up with a good name to represent exactly what it did...

https://www.npmjs.com/package/type-safe-validator

The ability of the TypeScript compiler to allow this stuff continues to make it one of my favourite languages to work with, despite it still being JavaScript underneath.

Re:Designing the perfect TypeScript schema validation library by colinmcd on Thursday March 12, 2020 @08:23PM (#22563507)
I guess it's something in the air! Given the popularity of the other libraries, it's surprising that there's isn't an optimal one.

And yeah, unless you've gone down the rabbit hole of type safety obsession, it's hard to understand the necessity of this. I like that you specifically call out REST API validation in your docs...the difficultly of type safe API implementation was what drove me to build zod.

I'm using Zod plus a hand-rolled codegen tool to implement an end-to-end type safe RPC API that validates all data at runtime AND generates a statically typed Typescript SDK for use on the client.

PS If people like the sound of that I might publish that too. Let me know if it sounds interesting.

Re:Designing the perfect TypeScript schema validation library by Lapland on Tuesday March 17, 2020 @04:18AM (#22602815)
I think it sounds super interesting, would love to see how you've solved it :)
Re:Designing the perfect TypeScript schema validation library by sakagami0 on Thursday March 12, 2020 @07:31PM (#22563169)
Wow I love it. It seems like a lot of us have encountered similar problems with TS. I am planning to shift what I made into something like yours, using right/left instead of throwing errors.

https://www.npmjs.com/package/presi