Everyone's talking about Valibot

  Рет қаралды 46,258

Matt Pocock

Matt Pocock

Күн бұрын

Valibot repo:
github.com/fab...
Become a TypeScript Wizard with my free beginners TypeScript Course:
www.totaltypes...
Follow Matt on Twitter
/ mattpocockuk
Join the Discord:
mattpocock.com...

Пікірлер: 127
@garretmh
@garretmh Жыл бұрын
It’s worth noting that tree-shaking isn’t always available. It requires a build step. However, valibot is structured so that you can still only import what you actually need by using multiple direct imports, which is nice of them.
@sitcomrave
@sitcomrave Жыл бұрын
For server side applications, runtime memory allocation is much more important than bundle size. This is where libraries like typia, ts-runtime-checks excel. They generate validation and error handling code at compile time.
@82TheKnocKY
@82TheKnocKY Жыл бұрын
Very generally, memory allocation is also very related to speed as allocating memory on the heap and then garbage collecting it is very cpu expensive. For frontend though, the bundle size is arguably more important than speed.
@BinaryReader
@BinaryReader Жыл бұрын
The problem with typia is you need to take on a lot of non-standard compiler plugins to make it work. It doesn't integrate at all with watch reload tooling, doesnt work in Deno (not least without adding extreme compiler delay (there's a reason people use swc)), and the code and schemas it emits are utterly archaic (I can't even use the schemas as they're structured so poorly we tried using it for Swagger generation...just nope). Using it also locks you into the tool and associated poor workflows for the long term.....pass. Can't recommend it, had some wins early but turned into a footgun and ditched it for TypeBox. Havent used ts-runtime-checks, but looks like it does the same thing...so pass again. Need proper TS tools from Microsoft to solve compiler emitted types really...and they need to integrate with swc and esbuild and be fast.
@ChristofferLund
@ChristofferLund Жыл бұрын
Pretty cool stuff! Not entirely sure about the naming though. The name seems like it will be confused with all the AI stuff these days, but perhaps it will gain extra popularity because of the confusion. Jury is still out on this one.
@thedelanyo
@thedelanyo Жыл бұрын
Just like JavaScript did with Java 😅😅😅😅
@yegorzakharov8514
@yegorzakharov8514 Жыл бұрын
Tbh I thought it was a cheat for Valorant until I saw its from Matt 😂
@unsaturated8482
@unsaturated8482 Жыл бұрын
Yeah it's no bot. But just a bunch of glorified templates
@muhamedadel5859
@muhamedadel5859 Жыл бұрын
Hardest thing in programming is ... ?
@AngelHdzMultimedia
@AngelHdzMultimedia 5 ай бұрын
@@thedelanyo I'm gonna start calling JavaScript "EcmaScript", and TypeScript "Typed EcmaScript". 👀🤣
@yapet
@yapet Жыл бұрын
The problem with zod treeshaking IS NOT import * as z! I’ve seen bundlers remove unreachable things from namespace imports (unless you are doing dynamic lookups). The problem is that everything is attached to the prototype. If you import one validator, you have to import every other one (since all of the properties like .optional have to be present) This is exactly the reason why I’m excited for the pipeline operator. Should bring analizability of pure functions, and dx convenience of method chaining together. Wonder how this is going to impact library design, and if we are to see the move away from putting things onto the prototype just to get method chaining working.
@AngelHdzMultimedia
@AngelHdzMultimedia 5 ай бұрын
+1 I'm always checking the status of the pipeline operator proposal... my sanity depends on it.
@yuryimbro7531
@yuryimbro7531 Жыл бұрын
Rewriting a library that is 13.1 kilobytes in size to reduce bundle by 10-12kb, really? Isn't it going a little bit too far? Also, IMO, very questionable naming of functions such as 'email', 'object', 'string'. I don't think it's too uncommon to have a 'const email = '...';' somewhere in your code, so you'll end up either renaming that or the imported function. While 'z.email()' doesn't conflict with existing variables and also is immediately obvious to readers of the code.
@andreas.soderlund
@andreas.soderlund Жыл бұрын
A problem with most JS/TS validation libraries, except Zod, is that it's not possible to introspect the validation schema. So you're getting locked into the library-specific schema with no way of determining properties at runtime, which is essential in form validation libraries to generate default values for type safety, web browser constraints, etc. Without a validation standard it's hard to do anything about this, and it's easy to overlook when just looking at speed and size.
@BinaryReader
@BinaryReader Жыл бұрын
Try TypeBox, it does everything Zod does, but is based on the JSON schema standard (and to reflect you reflect on that schema) It's as close to a standard type schema as exists.
@andreas.soderlund
@andreas.soderlund Жыл бұрын
​@@BinaryReader TypeBox works as well, but as you say it's close to a standard, not an accepted standard. Which is the real problem - but even if it was, it's not that much fun to build a library if you have to adhere to a dry specification. I guess that's why we have a dozen libraries, doing the same thing (as projects like typeschema shows when unifying most of them on the validation level), competing for microseconds (that's more fun), ignoring things like DSL lock-in and lack of introspection. Otherwise, why this fragmentation for something as fundamental as type validation? Didn't we learn anything from the browser wars?
@joelv4495
@joelv4495 Жыл бұрын
@@andreas.soderlund TBH, the lack of "standards" is a problem that will probably never go away in the JS/TS ecosystem, simply because the languages that have standards, by contrast, were "sponsored" by a company from the beginning.
@Guergeiro
@Guergeiro Жыл бұрын
It's my understanding that you can import stuff from zod without using z. I think you can import { object } from "zod".
@thunfisch987
@thunfisch987 Жыл бұрын
Exactly
@thunfisch987
@thunfisch987 Жыл бұрын
You can also do import * as z from 'zod' Where you have the z. Schema but sadly no piping
@Ctrl_Alt_Elite
@Ctrl_Alt_Elite Жыл бұрын
​@@thunfisch987so could you not do the same with valibot? Import * as v. Then v.object(). Would that remove benefits of treeshaking etc too?
@thunfisch987
@thunfisch987 Жыл бұрын
@@Ctrl_Alt_Elite that also works and is also tree-shakeable
@Vierone
@Vierone Жыл бұрын
but if you import 'string' you are adding methods like 'string.min' 'string.max' to your bundle even if you don't use it.
@FabianHiller
@FabianHiller Жыл бұрын
Thank you Matt!
@Mitsunee_
@Mitsunee_ Жыл бұрын
just tested it and you can indeed also import from zod like this. Made a quick dummy schema with import { object, string } from "zod"; and it worked perfectly fine. Ofc the import cost is a bit higher because it includes stuff like refine, transform and parse in the import, but that's honestly fine? I accidentally do this a TON when vscode doesn't seem to understand that I'm trying to write a generic type or converting a type alias to an interface (or viceversa) and it autoimports stuff like number or string from zod.
@mattpocockuk
@mattpocockuk Жыл бұрын
Whoops, my bad! Should have tested it on stream.
@ellipsoid8
@ellipsoid8 Жыл бұрын
Interesting one, my only concerns for now is long term support. If it is a students project, I’m not sure how long it will be supported
@FabianHiller
@FabianHiller Жыл бұрын
I am not "just" a student. I also have a company that will provide long-term funding for Valibot.
@ImperiumLibertas
@ImperiumLibertas Жыл бұрын
​@@FabianHillerconsider working on your communication skills while youre at it
@noquarter9700
@noquarter9700 Жыл бұрын
@@ImperiumLibertas no room for jaelousy in open source, brother
@emenikedaniel
@emenikedaniel Жыл бұрын
@@ImperiumLibertas Easy 🤣😂
@deeOOgh
@deeOOgh 10 ай бұрын
@@ImperiumLibertas I didn't interpret his comment the way you did, and I'm glad for the clarification!
@anasouardini
@anasouardini Жыл бұрын
Would I be wrong if I said: large projects would use most of Zod's imports and the tree shaking, after all, won't matter that much, and similarly for small projects, their overall performance won't mind an additional 8kb anyways. Overall, in most cases, people would prefer mature projects over a tiny bit "better" ones. Maybe that's why ZOD didn't care that much about starting with an obviously slightly better design. Or they were leaving room for competition??
@uziboozy4540
@uziboozy4540 Жыл бұрын
Large projects should use Deepkit. Why on earth would anyone want to use runtime functions to define non type safe schemas?
@mskzzz
@mskzzz Жыл бұрын
People add 41kB framer-motion for fade-ins or react-hook-forms (even worse, formik) for a single form, and here we are fat-shaming zod for being 13kB but being the absolute goat
@uziboozy4540
@uziboozy4540 Жыл бұрын
@@mskzzz goat? It's nothing compared to @deepkit/type lol
@rockstar-technology
@rockstar-technology Жыл бұрын
​@@uziboozy4540Sorry I'm not putting application critical functionality on a library with less than 2k weekly downloads...
@Rohinthas
@Rohinthas Жыл бұрын
A Bachelor's thesis?! As if my imposter syndrome wasnt bad enough... haha (mostly) kidding of course, this is really cool. I doubt it's meant to be a serious competitor (at this point), but it makes really good points about tree-shakeability that many projects could take a little bit more to heart! Maybe it goes somewhere, maybe not, fantastic work though!
@GLawSomnia
@GLawSomnia Жыл бұрын
so this is basically like momentjs vs date-fns (different usecase of course)
@ChristofferLund
@ChristofferLund Жыл бұрын
Except moment is a legacy atm though, just worth mentioning.
@8koi245
@8koi245 Жыл бұрын
​@@ChristofferLunddamm already rip
@ChristofferLund
@ChristofferLund Жыл бұрын
@@8koi245 yeah it's "done" so it's just maintaining. You could probably use moment just fine but I find myself just needing date-fns usually and enjoy that experience more.
@bishowpandey453
@bishowpandey453 Жыл бұрын
@ChristofferLund have you used dayjs?
@ChristofferLund
@ChristofferLund Жыл бұрын
@@bishowpandey453 I have not. Have you? Are you happy with it?
@khraks
@khraks Жыл бұрын
BTW - data validation is a subset of effect-schema capabilities, please take a look
@thi-m10
@thi-m10 Жыл бұрын
The good point is that we can use the Zod's docs meanwhile the Valibot's is still in WIP.
@jessta314
@jessta314 Жыл бұрын
Slowly but surely approaching Elm's Json.Decode package.
@SamualN
@SamualN Жыл бұрын
I migrated to it, it's pretty good
@pupfriend
@pupfriend Жыл бұрын
not going to worry about some tiny amount of kb difference when the marketing team adds in massive tracking scripts and massively unoptimized images
@asatorftw
@asatorftw Жыл бұрын
I cannot justify rewriting code for a couple of kilobytes.😅
@FunctionGermany
@FunctionGermany Жыл бұрын
i prefer the namespaced "z.object" because it's easier for autocompletion and readability, so easier to both write and read. not sure if the tree shaking advantages of this new library hold when a whole-module-import (whatever the correct term is) is used to get these same benefits.
@ivanpartida7467
@ivanpartida7467 Жыл бұрын
There’s also VineJS, which is maintained by the AdonisJS team and has an API similar to zod’s but much faster, or at least they claim it is.
@jma42
@jma42 Жыл бұрын
man living the dream of their college being able to have an actual computer science theory-heavy thesis and supported by two of the most iconic web devs in the world!
@NabekenProG87
@NabekenProG87 2 ай бұрын
I would be interested how this compares to superstruct, which also has a functional approach. Since this video, valibot has doubled its size to 10kB, zod to 14.2kB and superstruct is at 3.4kB. I find it hard to compare these numbers if they can change so drastically over time. Seems like some of them are smaller because they are just missing features
@Keisuki
@Keisuki Жыл бұрын
I'm not really knowledgeable about the whole node package ecosystem, so shout at me if I'm wrong, but I don't get it. The main purpose, as far as I see it, for object validation is when dealing with untrusted data from a client, say... on a backend server. But on a backend server, bundle size doesn't really matter as much, at least not in the realm of hundreds of bytes. I certainly far prefer the nice, easy-to-use builder chaining that zod provides over saving me from uploading an extra kb when uploading my backend app to S3.
@elbotho
@elbotho Жыл бұрын
I'd use this on the client to validate data returned by an external API for example.
@mattpocockuk
@mattpocockuk Жыл бұрын
It would also work really nicely for form validation.
@FunctionGermany
@FunctionGermany Жыл бұрын
in a perfect world you'd be right but in practice there are cases every now and then where you validate in the client. most recently i've had to come up with a flexible way to compose and store simple math formulas on a database. eval is not an option so i made my own format with JSON. it works great but with our backend it would have been incredibly complicated to set up validation for this JSON so that it adheres to the rules for parsing the formulas. since the formula is parsed in the client and the formulas are written manually to the DB by admins (trusted), there was no reason that we couldn't simply validate the JSON in the client. so the frontend will simply tell you if the stored JSON is invalid by using zod. and this isn't the first time i've ran into legitimate frontend validation.
@offroaders123
@offroaders123 Жыл бұрын
This looks great, definitely want to try it out!
@nikob381
@nikob381 Жыл бұрын
And here I thought this was going to be a video about Urbit. Still good to know though!
@stephenpaul7499
@stephenpaul7499 Жыл бұрын
It always bothered me that you have to decide between the autocompletion ergonomics that Zod provides vs the tree-shakability that Valibot provides. I think the only way for typescript to support both of these traits is if it had proper support for nominal types. I don't usually care for nominal types, but in this instance, it would be necessary AFAIK.
@FabianHiller
@FabianHiller Жыл бұрын
In the long run, we can achieve a similar or maybe even better developer experience through a VS Code extension for Valibot. Similar to Taildwind CSS extension.
@stephenpaul7499
@stephenpaul7499 Жыл бұрын
@@FabianHiller good point, thats another way it can be achieved. Would still be nice if typescript supported this.
@TheProcessor
@TheProcessor Жыл бұрын
Sorry if this is duplicate. I can't see my comments. Vladimir Klepov created banditypes at 400 bytes in Feb of 2023. Maybe this individual built off of his. 642 bytes gzipped according to bundlephobia.
@AngelHdzMultimedia
@AngelHdzMultimedia 5 ай бұрын
This video made me try Zod with pipeline operator in Babel. 🔥👀🤣
@thijskoerselman
@thijskoerselman 9 ай бұрын
Isn't bundle size just a lot less of an issue for backend? I always considered that the main environment for something like zod. For server-side I think I'd rather have the convenience of the z autocompletion. For lambda functions startup time I might be looking at bundle size, but I doubt this makes a noticeable difference there.
@ThomazMartinez
@ThomazMartinez Жыл бұрын
Using that with SolidJS project really nice
@feldinho
@feldinho Жыл бұрын
What I don't like about this kind of composable functions is that you usually get `these(like(declarations()))` (yeah, you gotta read it from inside out for the order of application). I know this is easy to solve with a custom pipe function, but I don't think it's great API design until we have a pipe operator in JS.
@mattpocockuk
@mattpocockuk Жыл бұрын
Agree strongly with that. The chaining is much easier to read.
@thunfisch987
@thunfisch987 Жыл бұрын
​@@mattpocockukzod is also treeshakable when you do import * as z from 'zod' which gives you the z. but does not have the piping (like valibot) It's also treeshakable when you do import {object} from 'zod' which then is the same as valibot
@thienhuynh7962
@thienhuynh7962 Жыл бұрын
@@thunfisch987 tree-shakable imports from zod doesn’t allow for method chaining as they are separated as individual composable functions. You’d have to do this: z.nullable(z.string()) Instead of: z.string().nullable()
@thunfisch987
@thunfisch987 Жыл бұрын
@@thienhuynh7962 yeah, i said that (called it piping instead of chaining)
@RussianFrontend
@RussianFrontend 10 ай бұрын
Hi Matt! and what do you recommend to use now for frontend react projects ?
@mattpocockuk
@mattpocockuk 10 ай бұрын
Zod
@seanlawton7681
@seanlawton7681 Жыл бұрын
Is there any real situation where this would result in a notable performance increase? Seems like a cool project, but I wouldn't find myself tearing Zod implementation out to replace it with this. Maybe in a new project.
@mohammadhadialiakbar4486
@mohammadhadialiakbar4486 Жыл бұрын
io-ts is even smallers, and it was the librar that zod have lots of its idea.
@mattpocockuk
@mattpocockuk Жыл бұрын
Just horrendous docs, though
@ReconNite
@ReconNite Жыл бұрын
I mean, this literally just looks like "superstruct" to me...
@leokiller123able
@leokiller123able Жыл бұрын
There is something I dont understand with these libraries, why not just use typescript if you want types ?
@ahora1026
@ahora1026 Жыл бұрын
How is this different from superstruct ? Sounds like the same thing, slightly different api
@FabianHiller
@FabianHiller Жыл бұрын
I think that Valibot has much more features. But I may be wrong. In any case, it is implemented differently internally.
@pfcjulius
@pfcjulius Жыл бұрын
The website for it doesn't even work, the buttons don't do anything lol
@moneyfr
@moneyfr Жыл бұрын
what about vs arktype?
@ronensuperexplainer
@ronensuperexplainer Жыл бұрын
I'm confused, as a professional software developer. I watched the entire video and I still have no idea what Valibot is.
@bryson2662
@bryson2662 Жыл бұрын
Looks cool but I've been using arktype and happy with it
@artist6000ish
@artist6000ish Жыл бұрын
This video is impossible to undertand without undertsand what Zod is. That's fine. But it would be nice it if was clearly indicated at the start of the video that the target audience is someone who needs to understand what Zod is. I had to stop, and look it up. There wasn't even a link to it, so I had to guess and type "zod js" , so I wont get a false positive with that guy from the phantom zone.
@bibblebabl
@bibblebabl Жыл бұрын
But how it affects DX when you need to import everything each time you want to use it, but you want to have autocompleting etc?
@FabianHiller
@FabianHiller Жыл бұрын
VS Code can import all this automatically and still give you suggestions. Of course, this is not quite as precise as with Zod. Maybe we will improve this with a VS extension. Alternatively you can also use a wildcard import.
@TheMsksk
@TheMsksk Жыл бұрын
Looks like pydantic for javascrpt
@shapelessed
@shapelessed Жыл бұрын
"with valibot you might be importing the wrong things" - Just add a "* as" to the import statement and go from there... You can replace it later.
@oscarljimenez5717
@oscarljimenez5717 Жыл бұрын
If you do that, you're importing everything from Valibot.
@lukemoralesTV
@lukemoralesTV Жыл бұрын
@@oscarljimenez5717 but that type of import is tree shakeable
@mattpocockuk
@mattpocockuk Жыл бұрын
Is it? Got any reference for that? I believe you - it makes sense that it would be easy to tree-shake - but just didn't know that was a thing!
@lucasayabe
@lucasayabe Жыл бұрын
Yes is easy to refactor back to individual imports using the replace all feature of the vs code
@thunfisch987
@thunfisch987 Жыл бұрын
That's also how you can have zod treeshakable
@dinoscheidt
@dinoscheidt Жыл бұрын
Yeah tree shaking is nice, but come on. When you are at the point to need an end to end validator, you need anyway almost all of this stuff. If you only validate an email field, you can also just copy past a very short REGEX expression that is even smaller.
@humongous1234
@humongous1234 2 ай бұрын
Zod is still better. Chaining functions is awesome.
@nomadshiba
@nomadshiba Жыл бұрын
i did this myself too
@NsHtxZekoo
@NsHtxZekoo Жыл бұрын
Valibot has a type performance issues for basic schema. merge() seems to be the issue. Basic schema cause type instantiation deep and infinite issue and poor intellisense performance
@AlpharderCodes
@AlpharderCodes Жыл бұрын
Zod is terribly slow. Also it doesn't allow to quickly navigate to type definition's properties from their implementations in IDE. You should really try Typia instead
@emarticor
@emarticor Жыл бұрын
superstruct has been doing this for ages
@uziboozy4540
@uziboozy4540 Жыл бұрын
Deepkit >
@vali69
@vali69 Жыл бұрын
Hey, I'm human, I swear!!!
@philheathslegalteam
@philheathslegalteam Жыл бұрын
Much slower unfortunately.
@uziboozy4540
@uziboozy4540 Жыл бұрын
Inferior to Deepkit
@fooked1
@fooked1 4 ай бұрын
Valibot went nowhere, and that's a good thing.
@gro967
@gro967 9 ай бұрын
Unfortunately zod is extremely slow and has one of the worst performances of all available validation libraries...
@healingwithlove8614
@healingwithlove8614 Жыл бұрын
0h we got aother zod
@bangunny
@bangunny Жыл бұрын
I will stick with zod
@REAZNx
@REAZNx Жыл бұрын
just isnt necessary
@savire.ergheiz
@savire.ergheiz Жыл бұрын
or you can just grab plain js method and use it instead 😂
@mixed_nuts
@mixed_nuts Жыл бұрын
What stops the typescript team from making all those just native?
@mohaniya15
@mohaniya15 Жыл бұрын
Typescript only runs during compile time and not during runtime. Zod runs at runtime. I dont know how you would make something that runs at runtime native to something that runs at compile time.
Enums considered harmful
9:23
Matt Pocock
Рет қаралды 206 М.
Infer is easier than you think
13:38
Matt Pocock
Рет қаралды 90 М.
GIANT Gummy Worm Pt.6 #shorts
00:46
Mr DegrEE
Рет қаралды 77 МЛН
Пришёл к другу на ночёвку 😂
01:00
Cadrol&Fatich
Рет қаралды 11 МЛН
Players vs Corner Flags 🤯
00:28
LE FOOT EN VIDÉO
Рет қаралды 55 МЛН
Everyone's talking about gql.tada
5:06
Matt Pocock
Рет қаралды 43 М.
as const: the most underrated TypeScript feature
5:38
Matt Pocock
Рет қаралды 119 М.
Новый Valibot - альтернатива Zod для валидации
17:36
PurpleSchool | Anton Larichev
Рет қаралды 6 М.
TypeScript Enums are TERRIBLE.  Here's Why.
14:05
Michigan TypeScript
Рет қаралды 68 М.
The TSConfig Cheat Sheet
5:36
Matt Pocock
Рет қаралды 35 М.
Zod Goes Where TypeScript Can't
8:11
Theo - t3․gg
Рет қаралды 56 М.
The Hidden Cost Of GraphQL And NodeJS
28:35
ThePrimeTime
Рет қаралды 192 М.
Generics: The most intimidating TypeScript feature
18:19
Matt Pocock
Рет қаралды 176 М.
How does ZOD work? Build it yourself!
14:12
Andrew Burgess
Рет қаралды 12 М.
GIANT Gummy Worm Pt.6 #shorts
00:46
Mr DegrEE
Рет қаралды 77 МЛН