arktype

A

arktype

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

Join

using an const array as a source for a string literal union

Given this: ```ts const weatherIcons = [ 'sun',...

ParseError: Root of kind union should be one of alias,intersection,unit,domain,proto

```ts import { type } from "arktype"; const Amount = type("string|number") .pipe((s, ctx) => {...

Type Magic: validation on type property

How to validate defs in object type properties? ```ts export type validateSchema< def, schema,...

Usage for HTTP validation

I'm looking to use Arktype as a Request/Response validator This comes with the following requirements: - Request body should be validated with deep reject unknownKeys so invalid requests are immediately 422 - Response should be validated with deep delete unknownKeys so local information can't passthrough - Response input should be cloned rather then inline-morphed (including key deletion) so you can pass in input objects as-is...

Can you create types with dynamic literals?

Say I have this function: ```ts const createType = <T extends string>(code: T) => { const literal: string = code; return type({...

Cannot assign to Type

```ts import { scope, Type } from "arktype"; const ValidationErrorResponse = scope({ ErrorDescription: {...

How to validate `Record<string, string>`?

My naïve attempt: ```ts const Response = type({ "*": "string", });...

Property 'name' is missing in type

```ts const MyErrorResponse = scope({ Error: { message: "string", code: "string",...

Type 'distillOut<T>' is not assignable to type 'T'.

```ts import { type, Type } from "arktype"; const test = <T>(validator: Type<T>): T => { const result = validator({});...

Wrapper around `type()`

In my configuration loader that I'm building, I have a "registry" pattern where I want to have developers declare the type schema of the config they expect, and then they need to register the config in order to get it loaded, looks something like this: ```ts const GoodConfig = registerConfig( 'GoodConfig', type({...

Runtime coercion

I'm building a system to load declarative runtime configuration from a couple different sources, all of which provide values as strings (env vars, AWS SSM Parameters). Currently I'm walking through the typeJson at runtime to build accessors for each field, such as joining field names with __ to build environment variable keys, and that is working great. I can cleanly detect when I reach a "leaf" type to load, and I either have a string or an object with a "domain"; my challenge is whether there is an elegant way of coercing the string I load into the type expected at this point (without making some huge imperative logic block). I'm hopeful there might be some clever thing under the hood that I can use in place of rolling my own....

Mapping types

Hello, is it possible do to code like this? ```ts const x = type({ a: 'string', b: 'string',...

How to improve error messages?

address must be a string and less than length 200 and more than length 50 and valid according to an anonymous predicate and valid according to an anonymous predicate and valid according to an anonymous predicate (was missing)
This is an example of a validation error message returned. How could I go about making that a little more human friendly?...

Pipe required before narrow

const myFunc = (v: string) => true;
const MyString = type("50<string<200").narrow((s) => myFunc(s));
const myFunc = (v: string) => true;
const MyString = type("50<string<200").narrow((s) => myFunc(s));
Results in error:...

Error transforming object

I'm having some trouble doing transforming some data

Problem with Out type

Type '(In: string) => Out<bigint>' is not assignable to type 'bigint'
Type '(In: string) => Out<bigint>' is not assignable to type 'bigint'

Problem with validation in 2.0 dev?

I'm using 2.0.0-dev.11 and cannot figure out why some very basic validation fails. Short example: ```ts import { type } from "arktype"; ...

out.summary returns only one error 2.0.0-dev.11

Hi, I am just wondering if I am using this correctly as I followed the new arktype tutorial I made the following schema and validated it However, it only gives me one error...

Referencing self

Hello, I have a type A ```ts const A = { hello: 'string', aArray: arrayOf(???)...

Export type to JSON and share it

Hello, I have two TS programs that should cooperate (A B), B import types and validates data, and A creates and "saves" the types. A rough idea ```ts // Program A import { type } from 'arktype' ...