arktype

A

arktype

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

Join

`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' },...

Merging types instead of using an intersection when using generics

I have a generic type like this one :
generic('T', 'M')([ 'T', '&', { metadata: { id: 'M' }} ])
generic('T', 'M')([ 'T', '&', { metadata: { id: 'M' }} ])
...

Generic & intersection

I'm looking to have a helper arkWithMetadata, which basically takes a base type and add { metadata: { id: <id> }} I wanted to write this : ```ts export const arkWithMetadata = type( '<doc extends Record<string, unknown>, id extends string>',...

Is there a way to morph an optional value back to a required one?

the example bellow always returns a number, but is typed as {PORT?: number | undefined}
const schema = type({
PORT: ['string?', '=>', (v?: string) => parseInt(v ?? '3000')]
})
const schema = type({
PORT: ['string?', '=>', (v?: string) => parseInt(v ?? '3000')]
})
...
No description

Generic modules, Enums and AnyOf

There are at least 3 threads asking for OneOf I suggest making a Enum generic (called OneOf maybe) that works as following: - it accepts an object definition O - it has a root type which allows any of the property values O[keyof O] - it is a module with all property types as its values, Module<{ [K in keyof O]: Type<O[K]> }>...

Multiple @ark registries detected

I'm receiving this error in a Nextjs app:
Multiple @ark registries detected. This can lead to unexpected behavior.
Multiple @ark registries detected. This can lead to unexpected behavior.
...

File type

I noticed you can do types like File, I was wondering if it's possible to do things like validate file size?

Type definitions must be strings or objects (was undefined)

Hello! When importing a module that is using Arktype, I get the error Type definitions must be strings or objects (was undefined). I am not sure what it means. What should I be looking for to solve it?...

Function which receives a arktype's 'type'

I'm trying to do something like this: ```ts async rateLimitedCallApi<T>(url: string, schema: Type<T>): Promise<T> { await this.rate_limiter.acquire(); ...
Next