arktype

A

arktype

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

Join

scope() how to bypass circular reference error?

I've implemented with Scope() successfully circular references, but somehow, I hit a limitation as this one still throws a circular reference error: ```ts const types = scope({ queryValue: "namedDocument", // As soon as I add here namedDocument the error appears...

How to integrate generics with extend that need to access a type in scope?

queryValueObject is currently not resolving, and I assume it's because type() is creating its own scope. The question is, how can I solve it then? ```ts scope({ queryValue: [...

Is there a way to preserve jsdoc in arktype?

I have this piece of code: ``` /** * Defines a {@link https://docs.fauna.com/fauna/current/learn/security/roles/#user-defined-role | user-defined role}. A role determines an authentication secret’s privileges, which control data access....

What is the arktype 2 syntax for inferring classes with a private constructor?

In Arktype 1.x I was writing: ```ts import { type, Infer } from 'arktype'; ...

How to create an array of type.instanceOf?

This doesn't work: ```ts const documentReference = type.instanceOf(DocumentReference); scope({...

Validate Record values with morphs

Is it possible to do more advanced validation on Records? Ideally I'd like to apply any morph to each item in a Record. ```ts const nullNumber = type('number').pipe((s) => s ? Number(s) : null); ...

Testing a type in pipe

Congratulations on the 2.0 release, it's working great! 😀 Is it possible/best practice to run a type inside pipe? I'm having this test condition: ``` If string is a valid url, return URL Else return null...

configure({ onUndeclaredKey: 'delete' }) seems to allow extra properties through.

Or have I done something wrong ```typescript import { configure, type } from 'arktype' ...

Easier way to chain off of string.integer.parse?

I'm essentially trying to replicate this behavior from Zod:
const numberStringGreaterThan5 = z.coerce.number().gt(5)
numberStringGreaterThan5.parse("6")
const numberStringGreaterThan5 = z.coerce.number().gt(5)
numberStringGreaterThan5.parse("6")
...

Fail fast on union type

Hi i try to fail fast on union type as i know if there is an error , it's pointless to continue checking the union and get the right message and not the full list of all union message. For this i throw an error in the union branch and do a try catch on the type generated. Is there a clever/official way to do that: ```ts function arkTry<T extends (...args: unknown[]) => unknown>(fn: T) { return (...args: Parameters<T>): ReturnType<T> | ArkError => {...

Is ArkType compatible with the overrides made in `@total-typescript/reset`, or will stuff break?

This library overrides some TypeScript defaults for perhaps what could be considered more sensible defaults (I guess that's subjective). I'm wondering if could possibly break ArkType somehow? https://www.totaltypescript.com/ts-reset-article...

Zod "parity"? (nanoid, emoji,...)

Hello! ArkType is awesome! Been really enjoying replacing Zod in my project with it to try it out. 😁 I won't assume this is the case but are there any plans to implement some of the nice little extra "features" Zod has such as its nanoid and/or emoji validations?...

How can I globally configure a subtypes error

Problem: I want to configure all “string.email” errors to just be “Invalid Email”. I can almost accomplish this, I’m just missing a way to detect the subtype of the pattern at hand. Looking at the ctx object, code is just pattern. The closest thing I could do is match on the description, but that seems brittle. Zod seems to expose a .validation subtype to check on....

Is there a way to have defaults apply when a key is undefined, in addition to when a key is missing?

example: ```ts let objWithDefault = a.type({nameWithDefault: 'string = "foo"'}); objWithDefault({}); // this works objWithDefault({ nameWithDefault: undefined }); // this doesn't...

very silly question, is there an easier way to validate the length of a trimmed string?

type("string.trim > 2")
type("string.trim > 2")
errors with Uncaught ParseError: MinLength operand must be a string or an array (was never) ...

built-in stringify morphs

I see that there's built-in string parsing morphs, like string.integer.parse, but are there similar ones for the other way? e.g. number.integer.stringify

Intersection/Union Validation Errors

I'm a bit confused around how errors are calculated when validating objects using types involving intersections/unions. For example, given the following ```ts const base = type({name:'string'})...

'email' is unresolvable

I have a project that was pretty heavily invested in using ArkType for my validation, and with 2.0 coming out as stable i figured I'd start a branch and see if anything broke. While there might be other breaking changes, apparently using the email magic word is breaking. For example ```ts...