arktype

A

arktype

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

Join

Encountering "Uncaught SyntaxError: Identifier 'module' has already been declared"

I'm new to arktype and don't have a deep understanding of how web bundlers/etc work, so this may be a bit of a noob question. I'm using npm and parcel in our code base with several other package dependencies. The error above is referring to this line of code: ```...

Optional required pairs?

I have a type that has all optional properties. However I want to want to make 2 options a pair - if one exists, the other is required. An example: ```ts const props = type({...

Best way of sharing/compiling types?

I have two applications, in one I have defined types like ```ts const loginPayload = type({ email: email, password: "string", "+": "delete",...

Why are the partial operator `?` and explicit `undefined` incompatible?

I define the type: ```ts import { type } from 'arktype'; const checkType = type({...

Framework-level onDeepUndeclaredKey

Hi, thanks for this awesome library! I'm implementing arktype for my team and I plan on using it for DTOs which would validate the input and the output of our tRPC functions. For the output DTOs, I want to enforce the deletion of "deep undeclared keys" to make sure we don't leak any information, like this:...

email or empty string not working

export const feedbackSchema = type({
contact: 'string.email | string == 0'
});
export const feedbackSchema = type({
contact: 'string.email | string == 0'
});
...

Test that a string contains a substring?

Test that a string contains a substring?

Is there a recommended way to create a Record using a type as a key?

None of these seem to work: ```ts const stringKeys = type( "===", "CAR",...

`narrow` vs `satisfying`

I've ran across both functions, I can see the signatures are the same, but the type are not. I was wondering what the different is, between the two ?

Are there docs on how to do non-trivial self reference?

I can't seem to find them. I'm aware of the this keyword, but I'm looking to do something like: ```ts const example = type({ name: "string", selves: "this[]",...

Some performance struggles

Hey, I seem to be having some performance issues & I'm wondering if there are more optimal ways of typing stuff out 🙂 I've added the schema I'm working with bellow, importing anything except for the inferred type really seems to make things chug

Using scope with morphs

I store some data in a json file, so I'm using string.json.parse to read that data in and validate it. ```ts const UserConfigSchema = scope({ config: type("string.json.parse").to({ // ERROR:...

Passing an exported scope to a function (Type 'string' is not assignable to type 'never')

Hello, I have an exported scope that I'm trying to pass to a generic class to be used. ```ts // the class class SomeClass<TData extends any> {...

Is there a way to set a default value that is not valid?

This is due to svelte 5 - where you have to provide a meaningful non-undefined prop for bound values. e.g. for radio buttons, you need to default to "", not undefined. I am not sure how to define an Arktype type that accepts only an enum of values from the radio button, but defaults to empty-string. When I do the obvious inputType.default("") I get errors: ParseError: Default value is not assignable: must be "enum_option" (was "")...

Union Fallthrough?

I'm transforming some input using morphs like so: ```typescript const weightUnit = type({ value: 'number', unit: toStringUnion(weightAliasList),...

Defining and inferring a generic type defined inside a scope

I'm brand new to this library so I'm sorry if I'm doing something dumb, but I'm not sure how I can define a generic inside a scope. My broken code looks like this: ``` export const randomScope = scope({ foo: { bar: "'biz'",...

morphing to typescript type

I tried to do a narrow + pipe.try on type("string") to try to parse out a Temporal.ZonedDateTime type to sort of replicate what type("string.date.iso.parse") does, and it mostly works. But I've noticed if I infer the TS type I can't actually assign a Temporal.ZoneDateTime to the field, as tsc complains that the valueOf signatures are different. Is this supposed to work, or should I be venturing down the path of scopes and rootSchema instead? ```typescript const zonedDateTimeISO = type("string") .narrow((date, ctx) => {...

Generic middleware validator

Hello, I'm trying to write a middleware in my app that handles validating the incoming request body. It currently looks like this ```ts export function validateBody<T extends Type>( validator: T ): MiddlewareObj<ValidatedBody<T["infer"]>> {...

Compiling scope to interfaces

I have a huge scope and I want to extract 10+ interfaces from it, preferably in a way that would compile plainly to d.ts And then remake the scope with using those interfaces ```ts...

Union of generics

I've tried to write the following : ```ts export const arkQueryCriteriaValue = type('<Value>', [ { eq: 'Value' },...
Next