arktype

A

arktype

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

Join

Can the output of `.json` be used to construct an arktype schema?

For example: ```typescript const booleanJson = type.boolean.json console.log(booleanJson)...

Add property to object based on its data

I have a list of records (CSV to JSON) where each row has a variable numbers of attributes in its columns. It could be something like Attribute 1 name and Attribute 1 value, and so on for 2, 3, 4... On the output object, I'd like to make a Record where the name is the key, and it points to an object based on the attribute data (name and value in this case). So if the product type is (simplified):...

customize errors

i am quite new to this library and knowing that arktype support regexp validation, i am surprised, but now my question is how do i even explain this regexp to the user? i know that i can do ```ts...

validating 0x prefixed hex

How can I validate a hex string that is prefixed by 0x<hex> in typescript... ``ts type Address = 0x${string}`...

No validation of field until schema is complete ?

Hello, I am an experienced developer, unfortunately not experienced in TypeScript. I am in the process of learning, so sorry if this is trivial. I am trying to set up a form for a entity whose schema varies on some type field. I think I have found a way to express this in Arktype, but the validation doesn't seem to work as intended. Here is a minimal way to reproduce:...

Unsatisfiable type

I'm trying to do this intersection, that should definitely work with typescript types, but is not working on arktype, and returning this error: Intersection of { client_id: string, code: string, grant_type: "authorization_code", redirect_uri: (In: string ) => Out<URL>, + (undeclared): delete } and { client_secret: string, code_verifier?: never, + (undeclared): delete } | { code_verifier: string, client_secret?: never, + (undeclared): delete } results in an unsatisfiable type. I've tested it in the playground and it works, but not in my code and I can't figure out why. ```ts const secretOrVerifier = type( {...

Type '"DateValue | undefined"' is not assignable to type '"'DateValue' is unresolvableโ€Š"'.ts(2322)

Hello, i am an absolute beginner when it comes to ArkType and i am trying adapt my project while following allowing the https://arktype.io/docs/intro/your-first-type intro. When trying to adopt the example to my real life type, i am getting the error mentioned in the title. DateValue itself is a union type of some classes. What i am doing wrong?
No description

Can the JSON Schema be typed automatically?

I'm trying to use the generated JSON Schema inside forms in order to provide useful information to users, such as if the field is required/optional, if there is a max length limit, etc.. I'm using this schema: ```ts...

question about arktype => TS

I'm building OSS tooling for event-driven architecture and I have a question about ArkType, I'm currently using zod but I find it a bit cumbersome as I have to add 2 external packages to achieve what I'm doing. For some context I'm building over the wire typesafety and typegen, how I achieve this is I take in a schema, I turn that schema into a string representation of the type, then I send that over an event bus to all the other apps which listen to that event and then there I write it to the filesystem if it's local development. The current approach is this: ```ts // you have the class initialized:...

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?...
Next