arktype

A

arktype

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

Join

Can I make `string.yaml` like `string.json`?

I haven't been able to figure out a way of extending it with my own yaml https://arktype.io/docs/scopes#submodules 🤔

How to merge types with Generics

I'm trying hard to understand how to work with generics (arktype and typescipt too). ```typescript export const paginationRequest = < const def extends object,...

Can Arktype create discriminated unions based on whether a key exists?

``` typescript const MasterSkinItem = BaseItem.merge({ "+": "reject", type: "'skin'", masterItem: "true",...

examples of URLSearchParams

are there any examples of using arktype to turn URLSearchParams into a well formed, typed object? I see things like Headers are supported as types, but didn't see URLSearchParams...

How to validate all properties without bailing early?

I am using Arktype to validate forms. I would like to show all problems with a form. I am using unions to show some form elements conditionally. ``` export const OtherPropertyRow = type.merge( {...

How do I get the input type for `type`?

```ts export function validateEnv<T extends Record<string, unknown>>( def: ?, ) { const schema = type(def)...

.partial() is ruining the error scope

When i add .partial() to my type it seems to ruin the custom error messages of the fields inside my type. I created a reproduction here: https://arktype.io/playground?code=import%2520%257B%2520type%2520%257D%2520from%2520%2522arktype%2522%250A%250Aconst%2520productBase%2520%253D%2520type%28%257B%250A%2509dates%253A%2520type%28%257B%2520start%253A%2520%2522string%2522%252C%2520end%253A%2520%2522string%2522%2520%257D%29%250A%2509%2509.array%28%29%250A%2509%2509.atLeastLength%281%29%250A%2509%2509.configure%28%257B%2520message%253A%2520%2522Datess%2520are%2520required%2522%2520%257D%29%250A%257D%29%250A%250Aconst%2520ticket%2520%253D%2520type%28%257B%250A%2509%2522...%2522%253A%2520productBase%252C%250A%2509type%253A%2520%2522%27ticket%27%2522%250A%257D%29%250A%250Aconst%2520merchandise%2520%253D%2520type%28%257B%250A%2509%2522...%2522%253A%2520productBase%252C%250A%2509type%253A%2520%2522%27merchandise%27%2522%250A%257D%29%250A%250Aconst%2520Thing%2520%253D%2520type%28ticket%252C%2520%2522%257C%2522%252C%2520merchandise%29%250A%250A%252F%252F%2520Throws%2520correct%2520error%253A%2520%2522Datess%2520are%2520required%2522%250Aconst%2520out%2520%253D%2520Thing.from%28%257B%250A%2509type%253A%2520%2522ticket%2522%252C%250A%2509dates%253A%2520%255B%255D%250A%257D%29%250A%250A%252F%252F%2520Throws%2520incorrect%2520error%2520because%2520of%2520the%2520partial%28%29%253A%2520%2522dates_redeemable%2520must%2520be%2520exactly%2520length%25201%2520%28was%25200%29%2522%250Alet%2520otherOut%2520%253D%2520Thing.partial%28%29.from%28%257B%250A%2509type%253A%2520%2522ticket%2522%252C%250A%2509dates%253A%2520%255B%255D%250A%257D%29%250A...

Parse / validate urlencoded object

When posting something like {foo[a]: 1, foo[b]: 2}, is it possible to constrain the keys to always have a string and the value to always be a number? In the same move, is it possible to convert that to a mapped object like qs would too? (foo: {a: 1, b: 2})

Is this the correct way to reference `root` in new scopes?

I'm working through using the scope/module interface, to define new app-specific helper keywords to use. There are a couple of cases where I want to have a new hierarchy of keywords, but I don't want to duplicate the constraint from the "parent" in the child. For instance, if I have something like (as a contrived example):...

Trying to use Arktype with nestjs module problems

I don't undestand why i'm getting problems with
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/kordian/Projects/kindora-backend/node_modules/.pnpm/arktype@2.1.20/node_modules/arktype/out/index.js from /Users/kordian/Projects/kindora-backend/dist/src/database/pagination.types.js not supported.
Instead change the require of index.js in /Users/kordian/Projects/kindora-backend/dist/src/database/pagination.types.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/Users/kordian/Projects/kindora-backend/dist/src/database/pagination.types.js:4:19) {
code: 'ERR_REQUIRE_ESM'
}
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/kordian/Projects/kindora-backend/node_modules/.pnpm/arktype@2.1.20/node_modules/arktype/out/index.js from /Users/kordian/Projects/kindora-backend/dist/src/database/pagination.types.js not supported.
Instead change the require of index.js in /Users/kordian/Projects/kindora-backend/dist/src/database/pagination.types.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/Users/kordian/Projects/kindora-backend/dist/src/database/pagination.types.js:4:19) {
code: 'ERR_REQUIRE_ESM'
}
...

Using ArkType with @google/genai

I had some trouble getting ArkType working with the latest Google AI SDK. Gemini complains about certain JSON Schema fields, so I had to remove them. This seems to work for my use case: ```typescript import { GoogleGenAI } from '@google/genai'...

Using an ArkType Generic within TS types.

How can I convert an ArkType generic to a TS generic? Something like:
export const SuccessResponse = type("<T>", { data: "T" });
export type SuccessResponse<T> = ??? // Goal: { data: T }
export const SuccessResponse = type("<T>", { data: "T" });
export type SuccessResponse<T> = ??? // Goal: { data: T }
...

string.date.parse does not work on cyclic objects

Hello, i did not find anything related to this, but if i have a cyclic type like this: ``` export const types = scope({ User: {...

Multiple Error Message using Arktype

plateDefinition: { rows: type('number>0').and(type('number<33')).configure({ message: 'Please enter an integer between 1 and 32.', }), ...

toJsonSchema question

I am working on something that needs to convert standard schema validators to json schema. For seemingly similar validators, I am getting different behaviors between zod4's new json schema generatation and the arktype json schema generation that is leading to errors ```typescript import { type } from "arktype"; import * as z4 from "zod/v4";...

Usage with JSON Schema

Hi all, I'm in the process of migrating my project from Zod to ArkType, but I'm running into issues while converting my AI SDK tool input schemas. The AI SDK requires non-Zod schemas to first be converted to JSON schema and be parsed with their jsonSchema helper, but when I do jsonSchema(arktypeSchema.toJsonSchema()) , I get the error:...

Is there an any type?

Hi there, I wanted to use an arktype for some Typescript, eg: ```...

handling fallback if error for regex

Is there any better way of doing default to undefined when failed one key in an object? ```typescript type({ some_key: type("string").pipe((v) => myRegex.test(v) ? v : undefined) })...

Unique attribute

Hi i created this schema to validate that a name is unique compared to existing name, however i wonder if it is possible to define the schema in a separate file and send the exiting names within the context Thank you for your help ``` const existingNames = ["a", "b", "c"]...
Next