arktype

A

arktype

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

Join

Section hero video

Hey, quick question: I would like to know how you made this video (on the home page of https://arktype.io/), what tools did you use ?

Is there a good way to use an array of fields mapped from an object into array as string literals?

So probably really simple and I am just missing something. I am trying to achieve the following: ```ts...

ArkType `toJsonSchema` returning not open-api compatible schema.

Hi, I am trying to get my arktype schemas working with fastify (was previously using zod but editor performance was tragic) so I started with setting OpenAPI. Zod tools use https://www.npmjs.com/package/zod-to-json-schema for this but since ArkType has a method built in I decided to use it the output however is different and zod's one actually uses enums/unions in a way that openapi can handle. ```ts...

Configure errors in a scope

Is it possible to set a expected/actual/etc handler for every type in a scope? I have something like this: ```ts const foo = type({...

How to choose "one of" in a type?

Hi there! ```ts export const user_find_one_controller_input = type({ "_id?": userApi.schema.user.get("_id"),...

Get ts type that accepts type arguments

I have a type that looks like this: ```ts interface PluginInstance<Input, TInput, Diff> { details: PluginDetails...

"Custom" type or equivalent to valibot.custom()?

I might just be missing something obvious, but I want to do something like this: ```ts import type { SomeType } from "some-external-library" ...

Omit is still parsing values

If I omit a field from a schema like so and the date_created is passed in, it will be validated. I expected omit to ignore / drop the field from the dataset when parsing: linkApi.schema.link.omit("date_created", "date_updated") ...

avatar must be a string (was undefined) although undefined it expected type

I have the following type: ```ts import { type } from "arktype"; export const profileData = type({...

How to create a type from json or jsonschema?

Thanks for this great library first! If a type can be serialized to an arktype schema by .toJSON (or a json schema by .toJsonSchema), how can I re-create that type with the json data? Another question, how can I check if an arktype schema extends another arktype schema? Thanks!...

TypeScript complaining about passing a type from a custom scope to custom helper function

I've got a bit of a wrapper around Arktype that i work with, honestly a very simple function ```ts export function validateObject<T extends Type<any>>( obj: unknown,...
No description

Early codependent field validation

I’m making a signup form following the example here https://arktype.io/docs/expressions#narrow If you add another field, e.g. email, the narrow doesn’t run until email is valid. After reading other posts, I believe this is intended behavior. So then I went to try and add the .narrow into confirmPassword, but the type of ctx.root ends up being unknown, since we’re still validating the type, which makes sense....

how to fail validation quickly

I have a union of types where each has a top-level field with a literal version number. When valid data is given, arktype can very quickly discriminate between the models and return a result, but in instances where something is wrong (but the version field is present) and the input is large, it takes a very long time to reject (10s of seconds). So I'm curious to understand why this is (what's happening when validation fails that doesn't happen when it succeeds?), and if it can be improved?

flatMorph in a type

I'm trying to use flatMorph to generate dynamic template literal keys for a type but it's becoming unknown. ``` const test = flatMorph( Array.from({ length: 15 }, (_, i) => i + 1),...

can `optional()` be used with a thunk?

I want to do something like this (to allow null values to be ignored): ``` export const mod = scope({ Nested: { something: "boolean",...

Is there a better way to do '.or' ?

We have some complicated union types. I am finding that doing '.or' off a arktype is going to cause a ugly nesting. I am hoping there is a better way to use 'or', pehaps there is some util i dont know about? See screenshots of chained or vs the idea or an or util....
No description

Type is not assignable to type (unions)

I am passing a typescript type into arktypes 'type' function, the type i am passing is has 2 union fields. It seems arktype expects the typescript union fields to have the same string formatting as itself which looks like a bug. See the screenshots and let me know 🙂...
No description

Inference on Mapped Types with Exhaustive Switch Possible?

Is it possible to get inference with an exhaustive switch with arktype using mapped types For example, in the switch statement below im using mapped types to limit the possible type that can be inferred in each case. I want to try to get the type system to know that under each case only one possible type is possible so i want it to show me the correct fields i can select from ```...
No description

is there a way to have an async morph?

```ts const formSchema = type({ appId: 'string', nodeId: 'string', id: type('string | undefined').pipe((v) => v ?? nanoid()),...
Next