arktype

A

arktype

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

Join

inferred type of '...' cannot be named without a reference to '...'

I found this in an old question from about a year ago when running into this issue in the process of adding type safety to Waku (new react framework by dai-shi) link to error I plan to use type annotation to unblock this per the recommendation here I wanted to re-ask this though, in case anyone here has come across a better way to fix this issue with a pnpm project over the course of the past year. @ArkDavid is this still something you see from time to time?...

Type instantiation is excessively deep and possibly infinite

const A = type("bigint").narrow(() => true).pipe((v) => v.toString());
type A = typeof A.in.infer;
const A = type("bigint").narrow(() => true).pipe((v) => v.toString());
type A = typeof A.in.infer;
Produces error:...

Extracting intent into runtime

Hello! What is the canon way to extract keys from types like these: ```ts...

string input, number output

is there something like ```ts const input = '600'; const out = type('parse.number')(input) console.log(out) // 600 (number)...

Represent the File class

Hi! I want to make a schema for validating a form, and one of the elements of the form is going to be a file upload, so I would like to validate that the form is sending an instance of the File class, and then validate that this file size is smaller than a certain amount. Is there a way to represent class instances in Arktype? An example of doing this in Zod would be: ```ts const schema = z.object({ image: z...

Any way to tell if a custom description has been provided?

Is there any way to tell if a custom description has been created for a type? For example, let's say I have this, which I'm using to validate some user input: ```javascript...

Converting Zod to Arktype

Hello! I'm really interested in using Conform instead of React Hook Form for better DX and server-side capabilities. However, it doesn't have Ark support yet, so I'll have to create my own simple patch. Are there by any chance some examples or comparisons between Zod and Arktype architectures to go off of when translating these files, namely to extract the name of the constraints like Array in runtime? ...

Record with number as key?

const A = type("Record<number, string>");
const A = type("Record<number, string>");
This throws error: ```...

Is there a way to rename the key in parse result

const t = type({name:"string"}) const result = t({name:"ankit"}) i want the result to be {alias:"ankit"} how can i replace the key "name" with "alias"...

Can I add a default value to a type if everything other satisfies in a union type

const type1 = type({name: "string"}) const type2 = type({city: "string"}) const union = type1.or(type2) const result1 = union({name:"ankit"}) const result2 = union({city:"Ajmer"})...

How to type an expressjs-like route handler based on the path pattern.

If I define an application like: get('/path/:id?q=:query', handler) is it possible to look at the structure of the string and infer the type of the parameters that are passed to the handler function as { id: string; query: string;}. Given the prevalence of this pattern, I'd expect that someone has attempted it before, but I can't seem to find it in the docs and/or discord....

Compiling to JavaScript results in `any` type

I have a TypeScript library that compiles down into JavaScript, and one of the d.ts files looks like this:
declare const Address: import("arktype/out/subtypes/string").StringType<import("arktype/out/keywords/ast").string.narrowed, {}>;
type Address = typeof Address.in.infer;
declare const Address: import("arktype/out/subtypes/string").StringType<import("arktype/out/keywords/ast").string.narrowed, {}>;
type Address = typeof Address.in.infer;
...

Was `any` removed?

I used to be able to do: type("any");. Now it's throwing error Argument of type '"any"' is not assignable to parameter of type '"'any' is unresolvableā€Š"'

Type instantiation is excessively deep and possibly infinite

const m = <T, U>(type: Type<T, U>) => {
return type.describe("test");
}
const m = <T, U>(type: Type<T, U>) => {
return type.describe("test");
}
...

Best way to pass `Type` around

Hello! First, thanks for building this really cool library šŸ™ I first heard of arktype while I was looking at the code of a framework called MUD, and while I was discussing CLI libraries with @frolic the other day, I thought that maybe it'd be a cool idea to have a CLI library that leverages arktype for arguments and options validation/parsing. I basically would like to have a function that receives args that are generated from arktype definitions. This is the code I have so far: ```ts import { type Type, type, validateAmbient } from "arktype"; import { type ErrorMessage } from "@ark/util";...

Default number

Hello! Setting this brings the expected result, when ran through inferAmbient: ```ts...

Optional property with const string array

Hello, the following
const x = ["a", "b", "c"] as const;
const myType = type({
"optional?": type("===", ...x),
});
const x = ["a", "b", "c"] as const;
const myType = type({
"optional?": type("===", ...x),
});
...

Extending types similar to an interface

How would one go about extending types similar to how one would extend an interface in TypeScript? It's really the only thing I feel like is missing for ArkType to be a viable alternative. A minimal example of what I want for ArkType, but written in TypeScript: ```typescript interface BaseTitle {...

Indexed Access Types

Hello, is it possible to recreate the SizeValues type below in arktype? ```ts const sizes = [ { label: "Big", value: "100kg" }, { label: "Medium", value: "50kg" }, { label: "Small", value: "10kg" },...

vscode intellisense errors on the same type definition in some files, but not others

e.g. the following type: ```ts const exampleType = type({ email: "string.email", });...