arktype

A

arktype

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

Join

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

Generic wrapper for drizzle-arktype functions

When using the drizzle-arktype functions I found myself writing the following two lines over and over again when validating my API requests: ```ts createInsertSchema(todos) .omit('id', 'createdAt', 'updatedAt')...

Resolving type and its nodes

I'm making a simple arktype to openapi transformer. What's the best way to get type's definition to use in logic? I mean literally like type('string')._def.type === 'string' etc.

Need help understanding this error

[0] ParseError: Alias 'type200' has a shallow resolution cycle: type200->type200 [0] at throwError (file:///workspaces/node_modules/.pnpm/@[email protected]/node_modules/@ark/util/out/errors.js:5:11) [0] at throwParseError (file:///workspaces/node_modules/.pnpm/@[email protected]/node_modules/@ark/util/out/errors.js:10:43) [0] at AliasNode._resolve (file:///workspaces/node_modules/.pnpm/@[email protected]/node_modules/@ark/schema/out/roots/alias.js:59:24) [0] at get resolution (file:///workspaces/node_modules/.pnpm/@[email protected]/node_modules/@ark/schema/out/roots/alias.js:46:29)...

Arktype codegeneration through openapi

Is it possible to generate Arktype types (to use as runtime type check) from a (Swagger) OpenAPI generated API? Our current approach is: Our BE updates Swagger -> we in FE download the newest file -> We generate the new API for us to use/ here Id also like to generate the arktype types -> We use it. ...

Advices for this use case?

Hi, any advice for improving these schemas? I'm pretty new to Arktype. ``` { "data": [...

type narrow issue on result

i have this really basic function ```ts function validateTokens( tokens: Partial<Tokens> | undefined...

customizing error messages

Hi, I'm just trying this library and so far looks very promising. I cannot, however, find anywhere if it is possible to have different error messages for different validators (for a single field)? For example in Zod I could do sth like this: z.array().min(2, 'choose at least 2').max(3, 'choose no more than 3') Is there an equivalent in ArkType?...

Arktype Error instance of?

Hi there. If I have ```ts...

Arktype pros and cons

Hey, we all know how great arktype is, currently I'm about to convince my CTO to use arktype for new projects, is there any indefeasible points for Arktype to win the debate apart from what already found on the web? 😂

Partial parse

Once in a while we encounter some data that's been stored away and the schema has changed over time. I'd like to parse it but also be forgiving enough to return the partially parsed schema. Something like this: ```typescript import { type } from 'arktype'; ...

functions that take in types

I have certain patterns i would like to make simpler like default arrrays or unique checks but I can't seem to figure out how to type them this is an example I would like to streamline ```ts...