arktype

A

arktype

This is a friendly space centered around ArkType, TypeScript's 1:1 validator (https://github.com/arktypeio/arktype)

Join

Performance comparison to Zod for piped string

Hello! I'm looking to implement a validator in a pretty performance critical area - so have been comparing some of the data contracts used, and in each test thrown together, ArkType is easily faster.... apart from one where a string is piped through a couple of stages The Zod equivilant is const zodTest = z.string().trim().toLowerCase().email().startsWith("info"); And for ArkType I've got const arkTest = type("string.trim |> string.lower |> string.email & /^info/");...
No description

does arktype understand "minimum 0 but not -0"?

in zod, even if you put .nonnegative it will still accept negative zero. would the same happen with AT?
No description

.onUndeclaredKey("delete") is breaking mongodbs _id field

Im not sure why this happens but when we have a type that has an _id which is a mongodb bson object, onUndeclaredKey(delete) causes mongodb to throw an error about the _id. If i use .onUndeclaredKey("reject"), that works fine. If i dont use onUndeclaredKey method at all mongo works fine. Its also worth noting the _id looks correct after parsing the data with arktype but for some reason mongodb does not like the _id after it has gone through .onUndeclaredKey("delete")...
No description

How can "string" type be not empty?

Without having to add ">0" to all my string types is there an easy way to ensure that type of "string" cannot be empty string? ``` type({ name: "string", // expect to be a value and not ""...

Passing a name for a primitive value?

Is there a way to pass a name to a primitive value being checked, so that in the error message you get shown "(name) must be..." like for object properties?

Can't infer type of schema when using "scope"

I am using arktype to parse data from incoming web requests. I define the schema and the parsed result will be passed into my handler. It looks like this and is working perfectly fine right now: ```typescript server.endpoint({ url: "PUT /admin/user/:id",...

schema key alias

Is there a way that I can create an alias to a key in the type? Like this: ```ts import { type } from "arktype"; ...

Custom message to formSchema in TanTack Form Standard Schema

How to customize error messages i this example? const formSchema = type({ firstName: 'string >=3', lastName: 'string >=3',...

How can define this type with arktype?

I'm relatively new to runtime validation and I'm having some trouble with arktype's syntax. This is the valibot's example that I want to replicate: ` metadata: v.optional(...

Pipe generic types

I'm trying to extract a generic type, but it seems like it's not possible, or am I mistaken? What I'm trying to do is to extract a generic property ```ts const genericType = type("<t>", {jsonValue:"t"}).pipe(({jsonValue}) => jsonValue)...

Can the output of `.json` be used to construct an arktype schema?

For example: ```typescript const booleanJson = type.boolean.json console.log(booleanJson)...

Add property to object based on its data

I have a list of records (CSV to JSON) where each row has a variable numbers of attributes in its columns. It could be something like Attribute 1 name and Attribute 1 value, and so on for 2, 3, 4... On the output object, I'd like to make a Record where the name is the key, and it points to an object based on the attribute data (name and value in this case). So if the product type is (simplified):...

customize errors

i am quite new to this library and knowing that arktype support regexp validation, i am surprised, but now my question is how do i even explain this regexp to the user? i know that i can do ```ts...

validating 0x prefixed hex

How can I validate a hex string that is prefixed by 0x<hex> in typescript... ``ts type Address = 0x${string}`...

No validation of field until schema is complete ?

Hello, I am an experienced developer, unfortunately not experienced in TypeScript. I am in the process of learning, so sorry if this is trivial. I am trying to set up a form for a entity whose schema varies on some type field. I think I have found a way to express this in Arktype, but the validation doesn't seem to work as intended. Here is a minimal way to reproduce:...

Unsatisfiable type

I'm trying to do this intersection, that should definitely work with typescript types, but is not working on arktype, and returning this error: Intersection of { client_id: string, code: string, grant_type: "authorization_code", redirect_uri: (In: string ) => Out<URL>, + (undeclared): delete } and { client_secret: string, code_verifier?: never, + (undeclared): delete } | { code_verifier: string, client_secret?: never, + (undeclared): delete } results in an unsatisfiable type. I've tested it in the playground and it works, but not in my code and I can't figure out why. ```ts const secretOrVerifier = type( {...

Type '"DateValue | undefined"' is not assignable to type '"'DateValue' is unresolvableโ€Š"'.ts(2322)

Hello, i am an absolute beginner when it comes to ArkType and i am trying adapt my project while following allowing the https://arktype.io/docs/intro/your-first-type intro. When trying to adopt the example to my real life type, i am getting the error mentioned in the title. DateValue itself is a union type of some classes. What i am doing wrong?
No description

Can the JSON Schema be typed automatically?

I'm trying to use the generated JSON Schema inside forms in order to provide useful information to users, such as if the field is required/optional, if there is a max length limit, etc.. I'm using this schema: ```ts...

question about arktype => TS

I'm building OSS tooling for event-driven architecture and I have a question about ArkType, I'm currently using zod but I find it a bit cumbersome as I have to add 2 external packages to achieve what I'm doing. For some context I'm building over the wire typesafety and typegen, how I achieve this is I take in a schema, I turn that schema into a string representation of the type, then I send that over an event bus to all the other apps which listen to that event and then there I write it to the filesystem if it's local development. The current approach is this: ```ts // you have the class initialized:...

Generic minimum and maximum

Is it possible to create a type that is generic over a min/max value? I wanted something like this: ```ts type('<min extends number, max extends number>', 'min <= number <= max')...