arktype

A

arktype

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

Join

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

Is there a recommended way to transform a type union into a discriminated union by adding a tag?

I'm not sure I'm describing this well, but I have a situation with two types that I am .or-ing together. It all works, but I'm interacting with a library that needs a discriminated union to function properly for type narrowing, and I am not sure how to add a discriminated union tag based on which type in the Or resolved (if that makes sense?) Here's a simple example to demonstrate:...

Is there a way to do a case insensitive literal match?

I can pipe a string.lower to a lower-case literal but that seems complicated for this.

Is there a way to perform schema parsing generically?

My reasoning is to integrate Arktype with https://effect.website/ This most simple example fails: ```ts function genericDemo<T>(schema: Type<T>, u: unknown): T {...

Use native ts type

I was wondering if I could use an already created type:
type BlockainsName = "bitcoin" | "ethereum" | "solana" | "polygon-pos" | "binance-smart-chain" | "avalanche"
type BlockainsName = "bitcoin" | "ethereum" | "solana" | "polygon-pos" | "binance-smart-chain" | "avalanche"
inside an arktype type declaration:...

ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options

Hello! When key isn't provided in the .map function, the above error is thrown. Not working code: ```ts...

Dynamic type based on another value

Given a theoretical example like this: ```ts const formDef = type({ agree: 'boolean',...

Why does an optional property add a " | undefined" instead of just being an optional property?

Hi, this feels like such a basic question that it probably has an answer, but I don't understand why marking a arktype property as optional not just makes the corresponding inferred type property optional, without adding an additional | undefined? I encountered something similar with zod which had the result that my zod-type and database generated type did not match although they should. Dummy example: ```ts const schema = type({...

Generic with Narrow/Morph

I want to make something like ```ts type UniqueArray<T, K extends keyof T> ...

Extracting defaults at runtime

Hello! What is the canon way to extract the default values of the type on runtime? I'd like to uuse the defaults from the type as defaults in a form. ```ts...

Ark attest cannot find module error

Hello! In a pnpm monorepo, with @ark/attest installed in the workspace root and running pnpx run attest trace ., I get the following output: ```...