arktype

A

arktype

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

Join

Type definitions must be strings or objects (was undefined)

Hello! When importing a module that is using Arktype, I get the error Type definitions must be strings or objects (was undefined). I am not sure what it means. What should I be looking for to solve it?...

Function which receives a arktype's 'type'

I'm trying to do something like this: ```ts async rateLimitedCallApi<T>(url: string, schema: Type<T>): Promise<T> { await this.rate_limiter.acquire(); ...

Conform to an existing type

Hello! Is there a way to force a def to conform to an existing typescript type? ```ts export const chatDef = type({ id: 'number',...

Using `atLeastLength` on morphed array

How do I do ```ts it("can use atLeastLength on piped array", () => { const SortedArray = type("string[]").pipe(s => s.sort()).to('string[]') const NonEmptySortedArray = SortedArray.atLeastLength(1)...

Partial Application of the validator

Is there any way to partially apply the validator for eg: ```ts const test = type({ name: "string",...

Customizing Error Messages

I've searched Github & Discord a bit and seen a few mentions of "full error customization", and am finding that I need it, but can't find any examples of it. I have a type: ```ts const form = type({...

v2 docs

I see the v2 docs mentioned frequently here and in GitHub, but I can’t find a link to them. Are they deployed? Even if they’re a WIP, they’d be extremely valuable to have I think...

Pipe chains don't work in rc13

I'm trying to make a logging wrapper to help me debug my Types but pipes don't seem to chain ```ts function logWrapper<T extends type.Any>(T: T): T {...

Node of kind optional is not valid as a required definition

Hello! Whenever I use a type with an optional key with a default value like this: ```ts const def = type({ 'agree?': 'boolean = true',...

Identifying a Date value in an object type

If I iterate through an object type, I can look at each key:value and do this: ```ts if (value.extends(type.number) { // Do some stuff } if (value.extends('boolean') { // Do some different stuff ...

Extenting Type interface

I want to make a custom function type({}).migrate() and add it to BaseType prototype How do I do it properly?...

Morph on failure

I have a type
const T = type({ id: "string>0", label: "string>0" })
const T = type({ id: "string>0", label: "string>0" })
and objects of type { id: string>0, label?: string>=0 }...

Property 'describe' does not exist on type 'instantiateType<inferTupleExpression<...>, {}>'

const create = <T extends number>(code: T) =>
type(["===", code]).describe("abc") as Type<T>;
const create = <T extends number>(code: T) =>
type(["===", code]).describe("abc") as Type<T>;
This used to work, but now in the latest version it results in error:...

Piping types no longer works

```ts import { type } from "arktype"; const Letters = type("'a'|'b'|'c'"); const Letter = type("string").pipe((s) => Letters(s));...

Post-morph constraints not checked if constraints not met on another property

If I have: ```javascript const schema = type({ name: 'string>3', 'age?': type('string.numeric.parse').to('number>18')...

Is there currently a known issue with arktype + trpc compatibility?

This is with latest RC.12 ``` TypeError: Cannot read properties of undefined (reading 'traverse') at assert (/node_modules/@ark/schema/out/roots/root.js:80:29)...

How would you define an object with optional keys, but require at least one of the keys to be filled

An example of a very basic schema:
const schema = type({ a: type.string.optional(), b: type.string.optional() });
const schema = type({ a: type.string.optional(), b: type.string.optional() });
...

`scope.validate` for a scope with imports

The usage of type.validate with custom existing scopes is straightforward - just use type.validate<def, scope.t> However, how do I validate a new scope definition with existing imports/exports? ```ts import { scope, type } from 'arktype' ...

Automatic "full" discriminated union

Hello, I have this code: ```ts const ActorInputSchema = type({ runMode: '"actor"',...