ArkType looks anything but ergonomic to me. Typescript in strings? Double level type encoding? It’s a miracle it can be 100x faster than Zod, but speed was never my issue with zod to begin with.
ArkType: Ergonomic TS validator 100x faster than Zod
61–70 of 72 posts
Re: ArkType: Ergonomic TS validator 100x faster than Zod
#62Really conflicted with TS. On one hand it’s so impressive that a type system can do these sort of tricks. On the other hand if we had type introspection at runtime we wouldn’t need any of this.
Re: ArkType: Ergonomic TS validator 100x faster than Zod
#63TS: "We have added types to javascript, everything is now strongly typed, and the compiler will pester you to no end until it's happy with the types." Me: "Awesome, so I get an object from an API, it will be trivial to check at runtime if it's of a given type. Or to have a debug mode that checks each function's inputs to match the declared types. Otherwise the types would be just an empty charade. Right?" TS: "What?"…
The debug mode sounds interesting at first thought, but quickly explodes in complexity when you deal with more complex object types and signatures. To enable automatic runtime validation for all cases, you would need to rewrite programs so thoroughly that you’re pretty much guaranteed to introduce bugs and behaviour changes that were not present in the source code.
In my opinion it’s great that TS draws a strict boundary to avoid runtime impact at all cost, and leave that to libraries like Zod, which handle dealing with external data.
> to catch all the "somebody fetched a wrong type from the backend" or "someone did some stupid ((a as any) as B) once to silence the compiler and now you can't trust any type assertion about your codebase" problems. Nada.
Those type casts are sure annoying, but what’s the alternative? Even in your hypothetical debug mode, you would not be safe here, since you’re effectively telling the compiler you know better and it’s supposed to transform that type, not assert it. Or do you want to remove the escape hatch „as“ is? Because that would be a major pain in the ass in situations where you just do know better, or don’t want to ensure perfect type safety for something you know will work.
You can’t make things idiot proof, no matter how hard you try. That doesn’t make preprocessing type hints useless.
Re: ArkType: Ergonomic TS validator 100x faster than Zod
#64Really conflicted with TS. On one hand it’s so impressive that a type system can do these sort of tricks. On the other hand if we had type introspection at runtime we wouldn’t need any of this.
What good would that do with making sure a complex form has been filled out completely? Without a way to meaningfully attach error messages and so on, that only solves a small subset of the problems libraries like ArkType, Valibot, and Zod solve.
Re: ArkType: Ergonomic TS validator 100x faster than Zod
#65In validation, it's never about speed. Is how you relate the schema tree to the error reporting tree. If you didn't already, you will figure that out eventually. If you mess that (either by being too flat, too customizeable or too limited), library users will start coming up with their own wrappers around it, which will make your stuff slower and your role as a maintainer hell. (source: 15 years intermittently mainta…
I find your last paragraph to be lacking. Would help if you elaborated more on the purported need for this "bridge" concept.
The need is obvious. As natural language becomes more proeminent in programming, there will be a need for a bridge to the older traditional paradigms. I can't give more details, it's the kind of thing you can't put in prose yet.
Re: ArkType: Ergonomic TS validator 100x faster than Zod
#66In validation, it's never about speed. Is how you relate the schema tree to the error reporting tree. If you didn't already, you will figure that out eventually. If you mess that (either by being too flat, too customizeable or too limited), library users will start coming up with their own wrappers around it, which will make your stuff slower and your role as a maintainer hell. (source: 15 years intermittently mainta…
Especially when unions are involved. We have a flexible schema for many parameters (e.g., X accepts an object or an array of them, and one object has some properties that could be an enum or a detailed shape), and both Zod and Valibot produce incomprehensible and useless error messages that don’t explain what’s wrong. We had to roll our own.
Re: ArkType: Ergonomic TS validator 100x faster than Zod
#67TS: "We have added types to javascript, everything is now strongly typed, and the compiler will pester you to no end until it's happy with the types." Me: "Awesome, so I get an object from an API, it will be trivial to check at runtime if it's of a given type. Or to have a debug mode that checks each function's inputs to match the declared types. Otherwise the types would be just an empty charade. Right?" TS: "What?"…
That isn’t what TypeScript is for, you’re describing a similar but unrelated problem, namely runtime type validation. There’s a reason why JSON.parse() returns any. However. TS allows to avoid logical errors in the program's source, which is a class of errors historically very important, since JavaScript is so highly dynamic. The debug mode sounds interesting at first thought, but quickly explodes in complexity when…
The closest thing to JavaScript would probably be Dart, now that it has sound types [1].
You’re right that it’s a pain in some situations.
Re: ArkType: Ergonomic TS validator 100x faster than Zod
#68With many TS features making their way into JS, I've sometimes wondered if TS is to JS what Sass is to CSS. I currently rely on TS, but I now consider Saas harmful [there being overlapping syntax w/ vanilla CSS].
What features are you thinking of? I hadn’t heard anything about TS types making their way into JS in any way (unless you count engines that can execute TS directly, but those just ignore the type syntax). That would be a massive change.
Re: ArkType: Ergonomic TS validator 100x faster than Zod
#69Earlier quoted context omitted.
What features are you thinking of? I hadn’t heard anything about TS types making their way into JS in any way (unless you count engines that can execute TS directly, but those just ignore the type syntax). That would be a massive change.
https://www.totaltypescript.com/erasable-syntax-only https://tc39.es/proposal-type-annotations/
The first one is removing a TS feature that failed to make its way into JS, and the second is about explicitly carving out a space in the syntax so that you can use TS (or Flow!) in JS codebases without being locked into any particular tooling.
Re: ArkType: Ergonomic TS validator 100x faster than Zod
#70Earlier quoted context omitted.
What good would that do with making sure a complex form has been filled out completely? Without a way to meaningfully attach error messages and so on, that only solves a small subset of the problems libraries like ArkType, Valibot, and Zod solve.
Look at how it’s done in Python, with Pydantic for example. The runtime information allows you to write plain typed functions (for example in FastAPI), and you can be 100% confident these are the types your function will actually receive at runtime, without having to write the types in a separate DSL. This is not possible in standard TS.
That doesn't work for JavaScript; you need full backwards compatibility at all times. Porting runtime type information to JS would change the language innards so much, it'd just be a different language in the end. At that point we could equally argue whether browser vendors should ship a Python runtime in browsers and add support for .