Tom
Aarktype
•Created by Tom on 2/18/2025 in #questions
how to fail validation quickly
I have a union of types where each has a top-level field with a literal version number. When valid data is given, arktype can very quickly discriminate between the models and return a result, but in instances where something is wrong (but the version field is present) and the input is large, it takes a very long time to reject (10s of seconds). So I'm curious to understand why this is (what's happening when validation fails that doesn't happen when it succeeds?), and if it can be improved?
3 replies
Aarktype
•Created by Tom on 2/13/2025 in #questions
can `optional()` be used with a thunk?
I want to do something like this (to allow null values to be ignored):
But I get the error:
Type definitions must be strings or objects (was Function)
I am needing to use a thunk because in my real case I am using a type defined within the scope. But maybe there's another way of achieving that?5 replies
Aarktype
•Created by Tom on 1/20/2025 in #questions
How to ensure optimal discrimination of union types?
I have a union of types, each of which has an attribute with literal values that can in theory be used to quickly identify an appropriate top-level type. They all look like this:
Is there some way I can setup my types or configure arktype such that it does a breadth-first discrimination of types within a union? does it store the result of the matching type somewhere? and finally - I'd like to understand this logic a bit more, but I am completely unfamiliar with the code base, if someone could point me at the code for resolving type unions that would be very useful. Thanks!
2 replies
Aarktype
•Created by Tom on 1/7/2025 in #questions
Can arktype drop data not covered by schema?
I want to regurgitate my input according to the schema model, e.g:
I'd want to make
out
contain only {name: "bob"}
. Is there a way to do this with arktype?8 replies