arktype

A

arktype

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

Join

Reference/use value from the same object during parsing

This has probably been asked before but didn't have any luck searching for an answer. I have a type like this: ```ts...

Renaming data sourced from an API

Finally getting a chance to play around wth AT again! I'm working with an annoying snake_cased REST API, wondering the cleanest way to rename keys? Just a manual morph I'd assume?

Easier default with morph

Below is an example of a morph where I try to parse a duration using luxon. Unfortunately, because of the defaultablility model, I think I have to do it this way. Is there any simpler way to achieve this outcome where I don't have to provide an ACCESS_TOKEN_TTL but if I do, I parse it as a Duration? ```ts import { ArkErrors, type } from "arktype"; import { Duration } from "luxon";...

How to retreive Error metadata

Hi! I'm creating an error using Arktype and I want to attach metadata so I can format the message later in my UI (React + react-hook-form): ``` return ctx.reject({...

Setting delete as default

Is it possible to set ``` { '+': 'delete'...

Separate the error messages for a specific form input from .summary

Hi I'm new to ArkType and I'm having a challenge with the error messaging. if I use dot summary i see all of the error messages but i'm not sure how to separate the error messages for a specific input. Any help will be most welcome.

How much work does defining a type do at runtime?

eg, is it likely to be a performance issue to call type('string.json.parse').pipe(MyPayload)(body) on every message we want to parse vs saving the functoin somewhere, or is it pretty lightweight? (Yeah, I can benchmark 🙂 but wondering if there's a recommendation.)

Create ArkType type from standard schema from other library.

Is it possible for me to integrate Standard Schemas from other libraries such as Effect.Schema or Zod with ArkType? I am using Effect and trying to use their Config module which seems built on their Schema type which can be exported to Standard Schema. I really don't want to redefine my schemas/types and am wondering if ArkType supports using other Standard Schema types to create its types?...

Redeclaring is normal? `no-redeclare` eslint rule

Hi, new to ArkType. I'm following the docs and doing stuff like const Foo = type(...); type Foo = typeof Foo.infer . eslint points out that this violates its no-redeclare rule. Of course I can just disable that rule globally or on each such line, but I'm curious if other ArkType+ESLint users do so, or have a different pattern, or a more precise way to disable it just for the ArkType case.

How to type URLs?

Hi, not sure if this is an ArkType or ArkEnv specific question but I'm using ArkEnv for strongly typed env vars. Everything in my config is typed except for my database url, which is currently typed as 'any'. If I remove the type() wrapper, then I get the following lint error: Type '"string.url"' is not assignable to type '"Reference to submodule 'string.url' must specify an alias​"' ...

Generate schema on the fly

Hello, I have a dynamic array of form field definitions that I want to generate validator schema from. Something like ```ts const fields = [ { label: "Field 1", type: "string", isRequired: true }, { label: "Field 2", type: "string", isRequired: false },...

Ensure a property is greater than a different property?

Is there a way to set a constraint for a number property so that it must be larger than a different property, like so?
type({ min: 'number > 1', max: 'number > min' })
type({ min: 'number > 1', max: 'number > min' })
...

How can I clone/make a new type without caching?

I want to assign a sort of metadata and additional methods directly to the type value, however, due to types being cached, those assignments will exist on every instance of that type signature. Is there anyway to disable caching for a single type, or clone an existing type so it has a new reference? Example of the sort of thing I want to do: ```ts const User = type({ id: 'string' });...

Creating array from another object

I'm new at arktype, just been trying to do UserSchema[]. I haven't seen anything on the docs, so how am I supposed to do arrays with types? What I have right now: ```ts...

Globally set `configure({ actual: () => "" })`

Hello, exploring your library, so far very good. Is it possible to do this globally? ```...

type.declare composition with undefined

Hello, I've been playing with arktype and trying to compose validators using preexisting types with type.declare .
When adding undefined this falls apart during compilation. https://stackblitz.com/edit/vitejs-vite-cpr8tkpa?file=src%2Fmain.ts...

Augmenting the default type scope

I'm trying to augment the default scope with additional types and re-export it so that it maintains all the built-in aliases for the subtypes that have been augmented. The ...type.keywords.string spreading mentioned in https://discord.com/channels/957797212103016458/1414659167008063588 just ain't doing it for me and I can't explain why. Here's what I've been trying, the compile-time failure case is at the bottom of this snippet -...

Wrapping arktype with utilities

We have an implementation of an in-house ORM layer that is built upon arktype. It's been really amazing to work with and supports some of our huge model types that have hundreds of fields while remaining snappy. We have a set of prebuilt core types that these models have to use in order for the downstream system to know how to persist and generate APIs around them appropriately. Unfortunately, I haven't been able to figure out how these could work with the core AT constructs because they encompass typing + defaulting behavior which we want standardized + metadata that the downstream systems use we define our core model types like this ...

Detecting validation errors across different ArkType versions/instances

Hey All, I've been using ArkType a bunch, across different packages. I've been loving it. One problem I've run into, is sometimes I'll have a situation where I have a type living in one package that I import into another package, and I'll be doing an instanceof type.errors and things don't work right because they aren't instances of the same imports. ...
Next