arktype

A

arktype

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

Join

Get values from type.enumerated?

```typescript const ValidationErrorCodes = type.enumerated( "INVALID_EMAIL", "MISSING_FIELD", "INVALID_FORMAT"...

Keep type name when using generic

I'm using a custom set of branding utilities (from ts-brand iirc). ```ts export declare type AnyBrand = Brand<unknown, any>; export declare type Brand<Base, Branding, ReservedName extends string = "type"> = Base & {...

Specifying a field name

Hello! I have the following schema: ```ts const schema = type({...

About using a generic pipe

Hello everyone, I am writing a schema in which one of the fields requiredness can be played with. I've come up with this type ``` const StringWithOptionalModification = type({...

Iterate over schema

Hello, I'm trying to create dynamic forms that would use ArkType to dynamically generate correct input type, but somehow I cannot find any good way to iterate over the schema. I've tried few things, and the only one that works is accessing schema.json.required which is not even part of TS type of JSON (it just exists at runtime). Is there any easier way? Basically what I'm looking for is for a way to turn some schema ```ts const schema = type({...

Matching on custom types

I have an array of errors (typed as any[]) that I need to transform. I’d like to break the transformation into several match cases. I’ve already done this with the Fluent API, but I’m not sure if the same approach works with the string-based API. ```tsx const FieldError = ({ title }: FieldErrorProps) => { const field = useFieldContext();...

empty string now but length string later?

For a few of my schemas i have them setup like this, which means the values can be empty string: ```ts export const telephone = type({ international: "string",...

object but not array

how do we declare a schema that only accepts plain json object like {} or {some: "key"} but not []?

Is there a way to create custom validator string syntax?

I would want to be able to extend the awesome string typechecking

Is there a way to attach custom metadata to types?

Tried using .configure but doesn't seem I'm able to attach arbitrary properties.

default value for array

Is it possible to set the default value for an array to an empty array? I'm trying to do something like this:
const Thing = type({
array: "number.integer[] = []",
})
const Thing = type({
array: "number.integer[] = []",
})
`...

Defining Records with narrowed keys

I couldn't find a way in the docs on object types (https://arktype.io/docs/objects) to define a record with narrowed keys. For example keys with no special symbols in them: BAD ```ts {...

default value for optional field

Hey! I have a question about handling optional fields with defaults. I want to define a type where a property is optional in the input, but its value should never be undefined. If the field is missing entirely, I want to transform the input so that the field is present in the result with a default value....

How to collect validation errors and custom errors in pipe

I have a pipe in which I want to add errors to the arkerrors array. But when there is an validation error, then only the validation error is outputted. ``` const pipedType = type({foo: 'string', bar: 'number'}).pipe((t, ctx) => { if (t.foo === 'foo') { ctx.error({...

Custom errors with morphs

Hello, I am trying to have custom error messages on morphs. Here is an example for a Port type. The error message is still the original one from Arktype. ...

Stringified array

Is there a type for stringified arrays i.e. elements joined with comma: "item1,item2,item3"?

Custom error message with conditions and i18n

Hi i am new here, and i try to create translated error messages. i have a schema like this. ```ts const Thing = type({ price: type('string.numeric>0').configure({...

Minimal array length - how to?

This page https://arktype.io/docs/objects#arrays says one can use [] > 1 to constrain minimal array length. However, this doesn't work: ```ts import {type} from 'arktype' ...

Help with Generic infered type

https://arktype.io/playground?code=import%2520%257B%2520type%2520%257D%2520from%2520%2522arktype%2522%253B%250A%250Aexport%2520type%2520RectItem%2520%253D%2520typeof%2520t.Rect.infer%253B%250A%250Aconst%2520%2524%2520%253D%2520type.scope%28%257B%250A%2520%2520%2520%2520Item%253A%2520%2522Rect%2522%252C%250A%2520%2520%2520%2520%2522Prop%253Ct%2520extends%2520string%2520%257C%2520number%2520%257C%2520boolean%253E%2522%253A%2520%255B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2522t%2520%257C%2520null%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2522%253D%253E%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%28prop%29%2520%253D%253E%2520prop%2520%253F%253F%2520undefined%252C%250A%2520%2520%2520%2520%255D%252C%250A%2520%2520%2520%2520SharedProps%253A%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520id%253A%2520%2522string%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520artboardId%253A%2520%2522string%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520parentId%253A%2520%2522string%2520%257C%2520null%2520%253D%2520null%2522%252C%250A%2520%2520%2520%2520%257D%252C%250A%2520%2520%2520%2520Rect%253A%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2522...%2522%253A%2520%2522SharedProps%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520name%253A%2520%2522%27rect%27%2522%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520fill%253A%2520%2522Prop%253Cstring%253E%2522%252C%250A%2520%2520%2520%2520%257D%252C%250A%257D%29%253B%250A%250Aexport%2520const%2520t%2520%253D%2520%2524.export%28%29%253B%250A RectItem is infering prop as: ``` { fill: string | number | boolean | undefined; }...

Prevent JsonSchema for type enumerated to become anyOf

Hello, when I have type.enumerated('foo', 'bar').or(type.enumerated('foo', 'bar').array()).toJsonSchema(), the returned schema is: ``` { "$schema": "https://json-schema.org/draft/2020-12/schema", "anyOf": [...