ostrowr / ts-json-validator

Let JSON play nicely with Typescript
MIT License
342 stars 7 forks source link

Strongly typed string formats #61

Open apoco opened 1 year ago

apoco commented 1 year ago
ostrowr commented 1 year ago

Awesome, thanks!

If you're using this in production, one thing to note is that I'm not actively maintaining this library (though I'm very happy to review PRs) and there may be better alternatives using more recent Typescript features. The problem with using this library in production is that it creates insanely complicated types that substantially slow down compilation.

That said, thanks for the fix, and I'll try to find some time to make some more improvements here soon!

jpage-godaddy commented 1 year ago

Awesome, thanks!

If you're using this in production, one thing to note is that I'm not actively maintaining this library (though I'm very happy to review PRs) and there may be better alternatives using more recent Typescript features. The problem with using this library in production is that it creates insanely complicated types that substantially slow down compilation.

That said, thanks for the fix, and I'll try to find some time to make some more improvements here soon!

Well it's been quite useful so far. I have a similar never-released code base that does something quite similar, and I know how complicated it can get (and mine was before conditional types were released!). I never figured out how to do references and abandoned the effort.

Know of any alternatives that fill this niche that you'd recommend (short of code generation)? I might use zod since in my case I don't need JSON Schema specifically, but I have other projects where I've considered using your library because I hate having to write two schemas or having a code generation script.

ostrowr commented 1 year ago

now of any alternatives that fill this niche that you'd recommend (short of code generation)?

Code generation is often a pretty good bet. It can get complicated with json schema but I've had a lot of success with json type definition (https://jsontypedef.com/)

If code generation is out of the question, I have to imagine Zod would work! This project would also definitely work for a small codebase, I just caution you that as it grows you may start running into compiler OOMs.

ostrowr commented 1 year ago

@apoco mind if I make the requested change and pull this in/cut a release?

apoco commented 1 year ago

Sure, that would be much appreciated, thank you.

On Tue, Jul 25, 2023 at 5:58 PM Robbie Ostrow @.***> wrote:

@apoco https://github.com/apoco mind if I make the requested change and pull this in/cut a release?

— Reply to this email directly, view it on GitHub https://github.com/ostrowr/ts-json-validator/pull/61#issuecomment-1650806523, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEGTFF7ZGZN2V2CKXWUIVTXSBTSHANCNFSM6AAAAAA2LPHPKE . You are receiving this because you were mentioned.Message ID: @.***>

ostrowr commented 1 year ago

For my own reference for this weekend, this is actually part of the spec (at least the latest version!)

https://json-schema.org/draft/2020-12/json-schema-validation.html#name-defined-formats

I have to read the spec more carefully to determine whether limiting this is actually correct; seems like custom implementations can define their own formats