arktype

A

arktype

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

Join

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()),...

is there a mustNotBe

currently I am using this as a workaround but I'd rather not implement the (was actual) part myself I would like maybe a mustNotBe or maybe a problem variant that doesn't overwrite the was stuff in the error string ```ts const formSchema = type({ name: type('string.trim').narrow((name, ctx) => {...

[attest] Getting `requested module ... does not provide an export` error for my bench script

Hi 👋 I'm having TS performance issues in my project. I think the offender is mainly tRPC with Zod and Drizzle, but I wanted to analyze a bit more before changing too much of my code. So I set up a very basic bench.ts script to check how long the tRPC appRouter would take to instantiate....

Uncaught (in promise) RangeError: Maximum call stack size exceeded

When using ArkType with svelte superforms, I'm getting the error: ``` justClone.js:14 Uncaught (in promise) RangeError: Maximum call stack size exceeded at String.toString (<anonymous>)...

Why is the generic expecting 3 options, although there is only one generic prop?

```ts import { type, scope } from "arktype"; const types = scope({ queryValue: "null | string | number | bigint | boolean",...

Is there an equivalent of zod.safeParse() for parsing incoming JSON requests?

Most people that I know that use Zod, use it mainly to parse incoming JSON request data into a schema. After reading through the docs I couldn't find anything that's really the equivalent of these methods, but wasn't sure if I'm just blind? Generic example: import { z } from 'zod'...

Has anyone been able to get `arktype` working in React Native/Expo?

I found this issue (https://github.com/arktypeio/arktype/issues/1027) but there doesn't seem to be any resolution (no pun intended...). I spent a couple hours trying different configurations but didn't have any luck. Just thought I would check if anyone has found a way to use arktype in a React Native project. Looks like a great library and I'd love to be able to pull it in....

scope() how to bypass circular reference error?

I've implemented with Scope() successfully circular references, but somehow, I hit a limitation as this one still throws a circular reference error: ```ts const types = scope({ queryValue: "namedDocument", // As soon as I add here namedDocument the error appears...

How to integrate generics with extend that need to access a type in scope?

queryValueObject is currently not resolving, and I assume it's because type() is creating its own scope. The question is, how can I solve it then? ```ts scope({ queryValue: [...

Is there a way to preserve jsdoc in arktype?

I have this piece of code: ``` /** * Defines a {@link https://docs.fauna.com/fauna/current/learn/security/roles/#user-defined-role | user-defined role}. A role determines an authentication secret’s privileges, which control data access....
Next