arktype

A

arktype

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

Join

Multiple error messages

I'm trying to migrate a zod schema to arktype. This is the zod schema I have: ``` import { z } from 'zod' export const createPasswordSchema = z...

Custom message not working

Hi there, For whatever reason when going off creating a custom message when doing: ```ts...

JSON Schema type inference

Hey, I'm unsure if I'm using @ark/json-schema incorrectly, but while supplying a const type that contains a JSON schema, I get unknown on the other side. Is this intended behavior, and if so, could it be tweaked to contain the type information inherited from the JSON schema?

Manually declare output type for a validation

Hello - I'm working on a library that emits types inferred from arktype validations. I want the inferred output type to use a named type (which i also export), instead of the literal inferred value of that type. So:...

dynamic key using string.uuid.v4 validating invalid strings.

Hi,
New to ArkType, so bear with me if this is answered, I couldn't find the relavent information on this topic. Here the link from playground: https://arktype.io/playground?code=import%2520%257B%2520type%2520%257D%2520from%2520%2522arktype%2522%250A%250Aconst%2520Thing%2520%253D%2520type%28%257B%250A%2509%2522%255Bstring.uuid.v4%255D%2522%253A%2520%2522%28number%2520%257C%2520string%29%2522%250A%257D%29%250A%250Aconst%2520out%2520%253D%2520Thing%28%257B%250A%2520%2520%2520%2520name%253A%2520%2522TypeScript%2522%252C%250A%2520%2520%2520%2520versions%253A%25207%250A%257D%29%250A I would expect the out to show ArkErrors, but it's showing json output. This gives errors for plain "string.uuid" but shows keys like 0000..00 & ffff...fff as invalid, while not accounting the actual incorrect keys....

implicit any if i import from another scope

if i have 2 files (testA.ts and testB.ts) which have the following contents: testA.ts: ```import {type} from "arktype"; import {modB} from "./testB";...

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