arktype

A

arktype

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

Join

Generic minimum and maximum

Is it possible to create a type that is generic over a min/max value? I wanted something like this: ```ts type('<min extends number, max extends number>', 'min <= number <= max')...

`.configure` not being applied

Hey all! I'm trying to use .configure to customize the error messages and it seems like it isn't being applied. For instance if you put this in the playground, you'll see that the error message is "Password must contain at least one character that isn't a letter or number". My expectation is that it would either be 'override problem' or 'override message' because that's what I've configured. Additionally, if I add console.log statements to the problem and message functions it looks like those never run....

It is compatible with Nuxt UI?

Some one knows if this library is compatible with ui forms? I would love to use it ! https://ui.nuxt.com/components/form#schema-validation...

How to ensure comma delimited set of numbers or fallback to undefined?

I'm trying to parse in some query string parameters, like "2,3,5" that I want parsed to [2, 3, 5]. I want to fail if any any number doesn't parse to an integer. When it fails I want to return undefined. Note that this will be part of a larger type: ```...

Fix Slow Types Warning When Publishing to JSR?

Does anybody know how to fix the slow types warning when exporting an arktype type validator in a JSR package? ``` error[missing-explicit-type]: missing explicit type in the public API --> /home/zicklag/git/muni-town/leaf/packages/leaf/sync-proto.ts:142:14...

onUndeclaredKey()

I'm encountering a discrepancy between the ArkType playground and my local Express development environment. This type definition works fine on the playground: ```...

Hint for discriminators in union for better error messages?

Hi, I had an issue similar to https://discord.com/channels/957797212103016458/1362079929986191552. I wanted to have better error messages in case of more complex discriminated unions, which internally aren't "detected" to be discriminated, thus falling back to an O(n) solution, which, in my case, is fine performance-wise, but not error message-wise. My concrete use case is a dynamic font where the user can select a value in radio group, causing other fields depending on the chosen radio item to be shown. Multiple radio items can lead to the same fields being shown (thus, having discriminators like 0|1 & 2|3)....

Discriminated union with union type discriminator gives wrong error messages

Let's say I have this type, right here: ```ts const Thing = type.or({ option: "'A' | 'B'",...

Optional union value?

Hey guys, if I have an object with a key that can either be a number or a string or can be missing. How can I validate it? Thank you

type inference resolves types from scopes to never in union

When using types from scopes in a union, arktype will resolve some of them to be "never", however if you insert their definition directly it resolves the type correctly Here is an example. If you paste this in the playground and hover of the out, the type will resolve to "never" in some places. Interestingly the .expression tab in the playground resolves the native Typescript expression correctly...

Standard Schema validation output issues can't be flattened

As far as I can tell the other validation libraries will have multiple issues for the same path, but for arktype they all get grouped in an intersection error type (if I have something like string < 10 & /some_regex/ and it fails both I feel like the default should flatten all errors in arktype to match the others behavior, or at least make it configurable? Or is the intention to just wrap our own StandardSchema around arktype where we flatten if needed?...

union of strings & Record as Generic argument

I'm using prisma and it generates Object for runtime and union of that object keys as type. Due to that I'm unable to use it in my type schemas: ```typescript // prisma export const GameTransactionType: {...

Type.any but with specific scope?

Is there a way to use type.any but with the scope bound to some type? My use case is that I have a special scope that does some magic for internationalization and I need a way to wrap (or just refer to) types externally (like on the website example) but with the scope bound to my special Scope...

Set object property alias for errors?

Is there a way to set an alias for a property name, which will be shown before the "must be" in errors? E.g. if I have a property 'dob' that holds a date of birth, I'd like the error to report "Date of birth must be...", rather than "dob must be..." I can see that I could configure a completely custom error message, but I'd like to be able to keep the standard errors, just change the name of the property....

branded types are not portable when declaration: true

Hi, I'm trying to export a branded type from a shared node package. The tsconfig has declaration: true because I want the type declarations emitted, but that seems to get me a type portability error:
The inferred type of 'Test' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@ark/util'. This is likely not portable. A type annotation is necessary.ts(2742)
The inferred type of 'Test' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@ark/util'. This is likely not portable. A type annotation is necessary.ts(2742)
just from ...

Is it normal for error messages / potentially behaviour to change depending on jitless?

I wanted to do some stuff with discriminated unions with jitless: true (due to a bug with jitless that has been fixed) and i noticed that the validation behaviour was different when i set it to jitless: false . Sadlly i didn't manage to reproduce the different validation behaviour but if you paste this into the web playground ```ts const formScope = scope({ "form.number": "string.numeric.parse",...

Empty string or number

I have this type that I want to reuse: ```ts const number = type("string") .pipe((s) => s || "0")...

Why ArkType when providing JSON Schema returns nulls as "{"const": null}"?

Hi, I want to generate OpenApi 3.0 from Arktype schema, in order to do so, first step in the pipeline is to convert to json schema using built-in toJSONSchema. Problem being that mentioned built-in function returns nulls from schema in a bit weird format with "const: null" and for example further when I'm using tools to generate openapi it just doesn't work correctly. That wouldn't be that big of a deal if not for types generation from openapi, where all those nulls are treaded as unknowns. I've tested both @hey-api/openapi-ts and openapi-typescript to generate types and both don't recognize it as null. For converting from json-schema to openapi I'm using openapi-json-schema. I would be very thanful if you could help me resolve that....

Is there a way to "deep" require a type?

I have a type with a lot of deeply nested types and a lot of keys in them are optional. I then want to make the same type but with all keys required i.e remove the optional. Is there an easy way to do this? I know you can use .require() but that only works on the top level keys, not the nested ones
Next