arktype

A

arktype

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

Join

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...

Scope and narrow

Hello, need to have nested objects but with only 1 key in each, i tried using narrow: ```ts export const SQLBoolOperatorSchema = type({ _eq: "string|number|boolean",...

`.out` is inferring `unknown`

```typescript import { ArkErrors, type } from "arktype"; const ToBigInt = type("string").pipe((v) => BigInt(v)); ...

How to build generic functions that use ArkType schemas?

I was a bit confused why this doesn't work. I seem to remember that it did work in an earlier version of ArkType. As soon as I replace Type<T> with Type<{}> in the signature it works šŸ¤”
No description

Recursive type problem:

Hello, I'm trying to define a recursive type with the library, but without success, i have the error remoteFieldSchema is unresolvable. What can i do: `const recTypes = type.module({ remoteFieldSchema: {...

cross posting from #typescript

noob question! how would i express this type using arktype syntax? ```typescript...

Recommended syntax for Higher Order Functions?

Hi all. Just found the project and started playing with it in a sandbox. I'm trying to create a module that will take an arktype as an input and return an updated arktype as the output while conserving the type safety. EG: ```ts import { type as arkType } from "arktype";...

Hi,

new to arktype, i have two questions: 1. i can't add a default for array ? like : foo:"string[]=['bar']" 2. given a type with all it's default can i create a concrete object from this type with all the default like: const foo=type({bar:"number.integer=42"}) and get back const defObj={bar: 42}...

How to ensure optimal discrimination of union types?

I have a union of types, each of which has an attribute with literal values that can in theory be used to quickly identify an appropriate top-level type. They all look like this: ```ts MyModelV1_0: { // model specific fields times: "number[]",...

Extract schema inside an array

Hello there, I'm new to ArkType, and I'm hitting an issue that I cannot seem to be able to solve... I'm trying to extract the runtime schema from within an array. Here is a simple example: ```typescript const simple = type({ id: 'number', array: type({...

exact length "string = 2"

Can we do something like stateCode: 'string.alpha = 2' ? stateCode: type.string.exactlyLength(2), works but curious if the = works...

Recursive types and d.ts files

I'm trying to define recursive types, where there's different kind of objects. One kind is a container, which can contain any kind of those objects, including other containers. My current approach looks like this: ```ts export const TestData = type.module({ objectData: "object | container",...
No description