6 ms·
This is just a link to the front page of possibly the #1 most popular type validation library in the ecosystem? Anyways, ya'll might want to check out up-and-co
by threatofrain 2y ago
This is just a link to the front page of possibly the #1 most popular type validation library in the ecosystem? Anyways, ya'll might want to check out up-and-coming Valibot, which has a really nice pipe API.
https://valibot.dev https://valibot.dev
- sergiotapia 2y agoA whole lot of yapping and ZERO code on the homepage. Authors should remove 90% of the stuff on that landing page, jesus! also since zod is the de facto validation lib, might be worth a specific page talking about why this vs zod. even their migration from zod page looks nearly identical between the two packages.
- petesergeant 2y agoOn the front page there is a prominent section addressing the differences from Zod, which appear to be “much better performance”
- rjknight 2y agoValibot is really nice, particularly for avoiding bundle size bloat. Because Zod uses a "fluent builder" API, all of Zod's functionality is implemented in classes with many methods. Importing something like `z.string` also imports validators to check if the string is a UUID, email address, has a minimum or maximum length, matches a regex, and so on - even if none of those validators are used. Valibot makes these independent functions that are composed using the "pipe" function, which means that only the functions which are actually used need to be included in your JavaScript bundle. Since most apps use only a small percentage of the available validators, the bundle size reduction can be quite significant relative to Zod.
- lolinder 2y agoIs there a reason why tree shaking algorithms don't prune unused class members? My IDE can tell me when a method is unused, it seems odd that the tree shaker can't.
- everforward 2y agoDoes that work for all class members? I think I've only ever seen that on private members, though I don't know whether that's because it's so much easier to check whether a private member is used or because an unused public member isn't an issue for eg a library. This feels like an issue that reduces down to the Halting Problem, though. Halting is a function that could be made a member of a class, so if you could tell whether that method is used or not then you could tell whether the program will halt or not. I think it's one of those things that feels like it should be fairly easy, and it's really really not.
- lolinder 2y agoComparing this to the halting problem isn't really meaningful here because even if you could make a full mapping (which yours isn't), you can prove that a rather large subset of programs halt, which is good enough for a tree shaker. I don't need to be able to eliminate every single unused function in every situation, but if I can prove that certain functions are unused then I can delete just those functions. We're already doing this regularly with standalone functions, so my question is just why this isn't done with class members.
- everforward 2y agoAh, I see your question now. Prototypes maybe? I’m not nearly a good enough JS dev to have a reasonable guess at that specifically. Being able to access class members using square bracket syntax with a variable also seems like it would make it really difficult to prove that something isn’t used. I’m thinking something unhinged like using parameters to build a string named after a class member and then accessing it that way. Dunno, I would be curious if someone has a definitive answer as well.
- aleclarsoniv 2y agoIt requires flow analysis, which is really hard to get right. I don't think there's a tree-shaking library that uses the TypeScript compiler API for static analysis purposes. Maybe because it would be slow? edit: The creator of Terser is working on flow analysis for his new minifier, according to him[1]. [1]: https://github.com/terser/terser/issues/1410#issuecomment-1710349693 https://github.com/terser/terser/issues/1410#issuecomment-17...
- crooked-v 2y agoValibot also has much, much more efficient type inference, which sounds unimportant right up until you have 50 schemas referencing each other and all your Typescript stuff slows to a molasses crawl.
- zztop44 2y agoAgreed. I recently moved a production app from Zod to Valibot for exactly this reason. I still slightly prefer Zod’s syntax but the performance issues were absolutely killing us.
- Escapado 2y agoNot only that, runtime schema validation was also way faster in my last project for larger arrays of complex objects with lots of union types. Went from 400ms to 24ms all else being equal. Since our validation was running on every request for certain reasons this made a huge difference in perceived performance for our users and less load on our servers.
- Timon3 2y agoI recently stumbled onto this when looking for alternatives, and though it might sound a bit extreme: the style of documentation means I'll never consider it for any project. It's strange and honestly somehow unnerving to read documentation written from a first-person perspective. Is there some good reason for this that I'm missing? Or am I just crazy and this isn't an issue for anyone else?
- Bjartr 2y agoI only see second-person "you" and not first-person "I" in the linked documentation. Am I missing what you intended to point out? In any case, this might actually be a good use for an LLM to post-process it into whatever style you want. I bet there's even a browser extension that could do it on-demand and in-place.
- Timon3 2y agoReally? For example under "Main concepts" on the "Schemas" site[0], I see stuff like this: - I support the creation of schemas for any primitive data type. - Among complex values I support objects, records, arrays, tuples as well as various other classes. - For objects I provide various methods like pick, omit, partial and required. - Beyond primitive and complex values, I also provide schema functions for more special cases. Same for "Mental model", "Pipeline", "Parse data", "Infer types", "Methods" and "Issues" - I'll assume the other sections also follow this style. That's all not showing up for you? While the LLM suggestion is nice, it's not something I'm comfortable with unless hallucinations are incredibly rare. Why would I use a library whose documentation I have to pass through an unreliable preprocessor to follow a normal style? [0]: https://valibot.dev/guides/schemas/ https://valibot.dev/guides/schemas/
- prophesi 2y agoIf they're part of Hacktoberfest, editing those pages to drop the first person perspective sounds like a pretty useful first contribution.
- 2y ago
- kaoD 2y agoDoes/will this correctly handle `| undefined` vs `?`, i.e. correct behavior under `exactOptionalPropertyTypes`? Zod doesn't (yet[0]) and it's been a pain point for me. [0] https://github.com/colinhacks/zod/issues/635 https://github.com/colinhacks/zod/issues/635
- x1000 2y agoI ran into exactly same pain point which was enough to nullify the benefits of using zod at all.
- aleclarsoniv 2y agoTypeBox[1] differentiates between optional and undefined. [1]: https://github.com/sinclairzx81/typebox https://github.com/sinclairzx81/typebox
- gkiely 2y agoIt does: https://valibot.dev/guides/optionals/#use-in-objects https://valibot.dev/guides/optionals/#use-in-objects import * as v from 'valibot'; const OptionalKeySchema = v.object({ key: v.optional(v.string()) }); type t1 = v.InferInput<typeof OptionalKeySchema>; // { key?: string } const UndefinedKeySchema = v.object({ key: v.undefinedable(v.string()) }); type t2 = v.InferInput<typeof UndefinedKeySchema>; // { key: undefined }
- mightyham 2y agoI'm currently using valibot and the author's associated modular form library in a production app and can vouch that it's been very pleasant to work with.
- Eric_WVGG 2y agoIs Valibot's error handling any good? Zod's is… like punishment for a crime I wasn't aware that I had committed.
- hyperbrainer 2y agoMaybe OP is one of the lucky 10,000. https://xkcd.com/1053/ https://xkcd.com/1053/
- deleted 2y ago[deleted]