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 }
Narrow inferIn vs inferOut
Maybe I misunderstood the expression, but I expected the In type to be
teamId: string | null
and the Out type to be teamId: string
. How can I achieve that, if not with narrow?
https://arktype.io/playground?code=import%2520%257B%2520type%2520%257D%2520from%2520%2522arktype%2522%250A%250Atype%2520In%2520%253D%2520typeof%2520Schema.inferIn%253B%250Atype%2520Out%2520%253D%2520typeof%2520Schema.inferOut%253B%250Aconst%2520Schema%2520%253D%2520type%28%257B%250A%2520%2520%2520%2520emails%253A%2520%2522string.email%255B%255D%2522%252C%250A%2520%2520%2520%2520teamId%253A%2520%255B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2522string%2520%257C%2520null%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2522%253A%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%28str%252C%2520ctx%29%253A%2520str%2520is%2520NonNullable%253Ctypeof%2520str%253E%2520%253D%253E%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520str%2520%21%253D%2520null%2520%253F%2520true%2520%253A%2520ctx.mustBe%28%2522a%2520teamId%2522%29%252C%250A%2520%2520%2520%2520%255D%252C%250A%257D%29%253B...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:...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"]...
Multiple error messages
I'm trying to migrate a zod schema to arktype. This is the zod schema I have:
```
import { z } from 'zod'
export const createPasswordSchema = z...
Custom message not working
Hi there,
For whatever reason when going off creating a custom message when doing:
```ts...
JSON Schema type inference
Hey, I'm unsure if I'm using @ark/json-schema incorrectly, but while supplying a const type that contains a JSON schema, I get unknown on the other side. Is this intended behavior, and if so, could it be tweaked to contain the type information inherited from the JSON schema?
Manually declare output type for a validation
Hello - I'm working on a library that emits types inferred from arktype validations.
I want the inferred output type to use a named type (which i also export), instead of the literal inferred value of that type.
So:...
dynamic key using string.uuid.v4 validating invalid strings.
Hi,
New to ArkType, so bear with me if this is answered, I couldn't find the relavent information on this topic. Here the link from playground: https://arktype.io/playground?code=import%2520%257B%2520type%2520%257D%2520from%2520%2522arktype%2522%250A%250Aconst%2520Thing%2520%253D%2520type%28%257B%250A%2509%2522%255Bstring.uuid.v4%255D%2522%253A%2520%2522%28number%2520%257C%2520string%29%2522%250A%257D%29%250A%250Aconst%2520out%2520%253D%2520Thing%28%257B%250A%2520%2520%2520%2520name%253A%2520%2522TypeScript%2522%252C%250A%2520%2520%2520%2520versions%253A%25207%250A%257D%29%250A I would expect the out to show ArkErrors, but it's showing json output. This gives errors for plain "string.uuid" but shows keys like 0000..00 & ffff...fff as invalid, while not accounting the actual incorrect keys....
New to ArkType, so bear with me if this is answered, I couldn't find the relavent information on this topic. Here the link from playground: https://arktype.io/playground?code=import%2520%257B%2520type%2520%257D%2520from%2520%2522arktype%2522%250A%250Aconst%2520Thing%2520%253D%2520type%28%257B%250A%2509%2522%255Bstring.uuid.v4%255D%2522%253A%2520%2522%28number%2520%257C%2520string%29%2522%250A%257D%29%250A%250Aconst%2520out%2520%253D%2520Thing%28%257B%250A%2520%2520%2520%2520name%253A%2520%2522TypeScript%2522%252C%250A%2520%2520%2520%2520versions%253A%25207%250A%257D%29%250A I would expect the out to show ArkErrors, but it's showing json output. This gives errors for plain "string.uuid" but shows keys like 0000..00 & ffff...fff as invalid, while not accounting the actual incorrect keys....
implicit any if i import from another scope
if i have 2 files (testA.ts and testB.ts) which have the following contents:
testA.ts:
```import {type} from "arktype";
import {modB} from "./testB";...
Get values from type.enumerated?
```typescript
const ValidationErrorCodes = type.enumerated(
"INVALID_EMAIL",
"MISSING_FIELD",
"INVALID_FORMAT"...