5 ms·
ArkType is a really interesting library that has a difficult time marketing itself. More than being a schema validator, it brings TS types into the runtime, so
by webdevladder 1y ago
ArkType is a really interesting library that has a difficult time marketing itself. More than being a schema validator, it brings TS types into the runtime, so you can programmatically work with types as data with (near?) full fidelity.
I've been evaluating schema libraries for a better-than-Zod source of truth, and ArkType is where I've been focused. Zod v4 just entered beta[1], and it improves many of my problems with it. For such a mature library to improve like this, v4 is treat and speaks volumes to the quality of engineering. But ArkType has a much larger scope, and feels to me more like a data modeling language than a library. Something I definitely want as a dev!
The main downside I see is that its runtime code size footprint is much larger than Zod. For some frontends this may be acceptable, but it's a real cost that isn't wise to pay in many cases. The good news is with precompilation[2] I think ArkType will come into its own and look more like a language with a compiler, and be suitable for lightweight frontends too.
[1] https://v4.zod.dev/v4 https://v4.zod.dev/v4
[2] https://github.com/arktypeio/arktype/issues/810 https://github.com/arktypeio/arktype/issues/810
- worble 1y ago> The main downside I see is that its runtime code size footprint is much larger than Zod. Yes, it unfortunately really does bloat your bundle a lot, which is a big reason I personally chose to go with Valibot instead (it also helps that it's a lot closer to zods API so it's easier to pickup). Thanks for linking that issue, I'll definitely revisit it if they can get the size down.
- notpushkin 1y agoPersonally, I find Zod’s API extremely intimidating. Anything more resembling TypeScript is way better. ArkType is neat, but ideally we’d have something like: export reflect type User = { id: number; username: string; // ... }; Edit: just remembered about this one: https://github.com/GoogleFeud/ts-runtime-checks https://github.com/GoogleFeud/ts-runtime-checks
- ChocolateGod 1y agoIt's not perfect and doesn't cover all of zods functionality (iirc coercion) but I've used https://www.npmjs.com/package/ts-to-zod https://www.npmjs.com/package/ts-to-zod before to generate zod schemas directly from types.
- crabmusket 1y agoThis is why I like libraries like typia or typebox-codegen; I'd prefer to write TypeScript and generate the validation, rather than write a DSL.
- sync 1y agoDefinitely check out Valibot as well, it may be the smaller footprint zod you’re looking for: https://valibot.dev https://valibot.dev
- Jaydenaus 1y agoThere's also zod mini now too https://v4.zod.dev/packages/mini https://v4.zod.dev/packages/mini
- epolanski 1y ago> it brings TS types into the runtime So...it's a parser. Like Zod or effect schema. https://effect.website/docs/schema/introduction/ https://effect.website/docs/schema/introduction/
- MrJohz 1y agoNo, it's more like a type reflection system, at least as I understand it. You can use it to parse types, but you can also do a lot more than that.
- vosper 1y agoCould you give an example or two of “more than that”?
- mintplant 1y agoYeah, you can walk the AST of your types at runtime and do arbitrary things with it. For example, we're using ArkTypes as our single source of truth for our data and deriving database schemas from them. This becomes very nice because ArkType's data model is close to an enriched version of TypeScript's own data model. So it's like having your TypeScript types introspectable and transformable at runtime.
- vosper 1y agoThat's neat, thanks!
- retropragma 1y agoTypeBox is similar by virtue of its goal of its runtime types matching JSON Schema's data model without need for conversion.
- epolanski 1y agoYou can do whatever you want with the AST in effect schema too, it's a parser with a decoder/encoder architecture: https://effect.website/docs/schema/transformations/ https://effect.website/docs/schema/transformations/
- CharlieDigital 1y agoI recently went down this same rabbit hole for backend and stumbled on Typia[0] and Nestia[1] from the same developer. The DX with this is fantastic, especially when combined with Kysely[2] because now it's pure TypeScript end-to-end (no runtime schema artifacts and validations get AOT inlined). I was so shocked by how good this is that I ended up writing up a small deck (haven't had time to write this into a doc yet): https://docs.google.com/presentation/d/1fToIKvR7dyvQS1AAtp4YuSwN6qi2kj_GBoIEJioWyTM/edit?usp=sharing https://docs.google.com/presentation/d/1fToIKvR7dyvQS1AAtp4Y... Shockingly good (for backend) [0] Typia: https://typia.io/ https://typia.io/ [1] Nestia: https://nestia.io/ https://nestia.io/ [2] https://kysely.dev/ https://kysely.dev/
- udbhavs 1y agoI was going to ask about how pure types would fill the gap for other validations in Zod like number min/max ranges, but seeing the tags feature use intersection types for that is really neat. I tried assigning a `string & tags.MinLength<4>` to a `string & tags.MinLength<2>` and it's interesting that it threw an error saying they were incompatible.
- retropragma 1y agoThat's because "minimum length" cannot be enforced in TypeScript. Maybe you already know this. I'm not a Typia user myself, but my RPC framework has the same feature, and the MinLength issue you mentioned doesn't crop up if you only use the type tags at the client-server boundary, which is enough in my experience.
- surprisedcat 1y agoThanks for sharing the deck! I had no idea Typia existed and it looks absolutely amazing. I guess I'll be trying it out this weekend or next :)
- CharlieDigital 1y agoThe docs have a bit of a rough edge because the author is Korean, but the examples are quite good and took me maybe 2-3 hours to work through. Once everything clicked (quite shortly in), I was a bit blown away by everything "just working" as pure TypeScript; I can only describe the DX as "smooth" compared to Zod because now it's TypeScript.