arktype

A

arktype

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

Join

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

TypeScript first - is possible or not? Can't remember :)

Hi folks! I'm not an ArkType regular as I would wish to be, so I may ask the same questions sometimes. Sorry for this. I wonder if it's possible to define TypeScript-first schema, and to pass the type as generic?...
No description

Can arktype drop data not covered by schema?

I want to regurgitate my input according to the schema model, e.g: ``` const user = type({ name: "string", })...

`.and` with default, expected behavior?

```typescript import { type } from "arktype"; const a = type({ someVal: type('string > 0')...
Next