arktype

A

arktype

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

Join

Help with Generic infered type

https://arktype.io/playground?code=import%2520%257B%2520type%2520%257D%2520from%2520%2522arktype%2522%253B%250A%250Aexport%2520type%2520RectItem%2520%253D%2520typeof%2520t.Rect.infer%253B%250A%250Aconst%2520%2524%2520%253D%2520type.scope%28%257B%250A%2520%2520%2520%2520Item%253A%2520%2522Rect%2522%252C%250A%2520%2520%2520%2520%2522Prop%253Ct%2520extends%2520string%2520%257C%2520number%2520%257C%2520boolean%253E%2522%253A%2520%255B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2522t%2520%257C%2520null%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2522%253D%253E%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%28prop%29%2520%253D%253E%2520prop%2520%253F%253F%2520undefined%252C%250A%2520%2520%2520%2520%255D%252C%250A%2520%2520%2520%2520SharedProps%253A%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520id%253A%2520%2522string%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520artboardId%253A%2520%2522string%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520parentId%253A%2520%2522string%2520%257C%2520null%2520%253D%2520null%2522%252C%250A%2520%2520%2520%2520%257D%252C%250A%2520%2520%2520%2520Rect%253A%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2522...%2522%253A%2520%2522SharedProps%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520name%253A%2520%2522%27rect%27%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520fill%253A%2520%2522Prop%253Cstring%253E%2522%252C%250A%2520%2520%2520%2520%257D%252C%250A%257D%29%253B%250A%250Aexport%2520const%2520t%2520%253D%2520%2524.export%28%29%253B%250A RectItem is infering prop as: ``` { fill: string | number | boolean | undefined; }...

Prevent JsonSchema for type enumerated to become anyOf

Hello, when I have type.enumerated('foo', 'bar').or(type.enumerated('foo', 'bar').array()).toJsonSchema(), the returned schema is: ``` { "$schema": "https://json-schema.org/draft/2020-12/schema", "anyOf": [...

"string.email>0" custom message not working

Hey for most types i use .configure({message: "Some error message"}) to customize error messages for fields. When i use it on email type it seems configure does not work the same: ```ts const stringEmail = type("string.email>0")...

Can I export and share all types on the global scope by default?

Heya, so I have a monorepo — it's a flat and ever-widening hierarchy; all directories have a direct connection to the root-level deno.jsonc, which is also where the arktype import happens. I would love it if I could just turn the loosey goosey dials up to max and use every type() declaration as an alias in any other part of the repo. Is there a built-in and/or elegant way to do this?...

[attest] Error scanning node_modules. How can I make attest trace work?

I'm trying to run attest trace to analyze my Next.js 15 monorepo package. However, I'm getting an error that attest cannot find a module. ```...

Auto throw if invalid

I have been looking through the docs and the API manually, but I haven't found something elegant that I am looking for. Is there a way to strictly throw an error if the validation doesn't pass? While I don't normally mind the explicitness of instanceof type.errors, I kinda prefer the method opt-in from Zod (parse vs safeParse) to make that choice. To be clear this would purely be a DX improvement to prevent typing out the error catching manually for type inference....

Modeling string template type

I have a type ``ts type T = { foo: '' | /${string}` }...

Discriminated unions with common field but different constraints

Hello, I am having trouble setting up a schema-system with my types. My code is type-first, so the schemas must be written in accordance to my types. My entities have a type property, which should be the discriminating property. Two types are possible: typeA and typeB. Both types of entities have a field named someField. By default, someField is nullable, meaning new types in the future should have it nullable. But typeA entities require someField not to be null. Creating the corresponding schemas lead to a type error when trying to match my types to the schema's types. ...

Throw an ArkError programmatically

Is there an easy way to throw an ArkError programmatically without defining a schema? I'd like to ensure a provided value is unique against my DB, so I'm looking for an alternative to this: ```ts...

Equivalent of Object.values for unions

hi there 👋 i'm trying to extract the values of an object in order to have it as a union of options and ended up with this right here is there a better maybe more elegant solutions to this? 😅...
No description

Is this a bug or user error? Re: Generic Argument Validation

``` import { scope } from "arktype" const versionScope = scope({ ProductHashKey: "string",...

Bracket Notation on Generics

Is there any way to do something like this? 🤔 ``` scope({ BaseType: { entityType: "string" },...
No description

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',...
Next