arktype

A

arktype

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

Join

Inferring generic types

Hi, I'm new to ArkType and have little knowledge about TypeScript generic. I wish I had something like below: ```ts...

Easy format errors like in Zod?

Hi, I can't find any errors formatting like in zod. https://zod.dev/ERROR_HANDLING?id=formatting-errors. I'm doing it manually now, maybe I'm missing something?)...

How to set an error message

Hey guys, I am trying to move this zod schema with arktype: ```ts const userZodSchema = z.object({ name: z...

undeclared keys in nested object

Hello. I want to use arktype for parsing objects in backend before sending them to client (mainly for removing unwanted keys), But when i use nested object types the undeclared keys won't get deleted ex:...

Narrow type based on another property's value

Hey, I've been using ArkType for a few days now - loving it so far. One thing I'd love to be able to do is narrow a type based on the value of another property in the object. eg. ``` const myType = type("'string' | 'Color'") ...

Generic loses literal

``` const nonEmptyStringOrNull = type("<s extends string>", [ "s | null | undefined", "=>", (s) => (!s ? null : s),...

How to set a custom message with object type?

Hi guys, I'm new to Arktype, I'm switching from Zod to Arktype with this code: ```ts export const TestSchema = z.object({ companyName: z...

How to represent arktype's Type types?

```ts export type ToolDefinition = typeof ToolDefinition.infer; export const ToolDefinition = type({ 'name': 'string', 'displayName?': 'string',...

how to do an union of dynamic literals ?

in valibot I use : const accessList = ["public", "premium"] as const; const accessSchema = v.picklist(accessList); in arktype I have to repeat the values ?...

onfail without importing config in every file?

is this possible? I'm trying to combine ArkType usage with neverthrow (i'm new to both so maybe i'm doing it wrong), but it seems like I'd want to wrap type validation in fromThrowable and throw the error, otherwise i'll stray from their Result type and will end up with what is basically ArkType version of a result type. from the docs i see i can config it to throw, but it seems a bit annoying to have to import the config along with type everywhere i use it which is what the docs seem to suggest should be done. any way around this?...

Is there an equivalent to Zod's `coerce`?

Hello, I am trying to convert the following Zod schema to ArkType: ```typescript const Params = z.object({ sort: z .union([...

Type instantiation is excessively deep and possibly infinite

I have a set of event validators within a scope defined as below. Once I add enough, I get the error "Type instantiation is excessively deep and possibly infinite". In the code below, remove "y" from the event key and the error will go away. ...

Password = Comfirm password validator

I may be stupid, but I am just learning arktype and was hoping to implement something like a zod refine. ```ts const passwordForm = z .object({...

How to combine multiple configure() calls

I noticed that if I call configure multiple times each next call wipes out the previous metadata. Here's a test example ``` test("arktype config", () => {...

Match `.in` with loose type

In docs there is example ```ts type Data = | { id: 1...

how to get a "hash" of the validator?

for TanStack Start server functions, I try to find out whether a input validator changed from one deployment to another. Is there a way in arktype (or ideally in standard schema) to get a hash or stringified version of the whole validator that I can use for that?

Validating Large JSON Schemas without high time/memory costs

I'm building a low-code tool for generating user interfaces. The UI structure is defined using JSON. The schema for the JSON structure is quite large. I have been using Zod for validation, but it is very slow—taking minutes to validate a single UI definition. I've tried switching to ArkType but it consumes too much memory, often causing the browser to crash. When it does not crash (and on the server where I can set a high memory limit) the call to type.module takes approximately 15 seconds, and then validation mere milliseconds. Given these performance issues, how can I efficiently validate large JSON structures against a schema without excessive time consumption or memory usage? Are there optimizations, alternative libraries, or hybrid approaches that could help?...

standard schema conforming schema in openauth not working seemingly exclusively with arktype?

i'm using the openauth library which is supposed to support standard schema for subjects definition. i get typesafe output with zod, and the docs use valibot so i assume those 2 work though with arktype i just get a generic v1.StandardSchema<unknown, unknown> type on the resulting object. with zod i get ```ts...

Easy way to validate enums

Brand new to Arktype(migrating over from Zod for perf reasons), and have a question about about handling enums. We have a fair number of enums that we use in our validation, example with Zod might be something like:
period: z.nativeEnum(Period),
period: z.nativeEnum(Period),
...

Get keys of object type

What's the easiest way to get the keys of an object type, and perhaps also some metadata for it? I see there's an keyof() method, but it has plenty of methods itself so I'm not sure what to use.