arktype

A

arktype

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

Join

Is there a way to parse Dates and date iso strings without losing toJsonSchema capabilities.

I'm trying to parse dates and also allow for date objects, but I also require toJsonSchema to work without exceptions. ```ts const dateParse = type("string.date.iso.parse"); const date = new Date();...

`string.integer.parsed` with limits

I need a simple port number, 1 < integer < 9999 Hovewer, I want to parse it from env string so I need string.integer.parse How do I make the limited parsed integer?...

Got syntax error in some browser

Encountered an unexpected error while compiling your definition: .. I guess it related to the token ??= syntax...

ToJsonSchema fails with narrow

Hi short question, i might be missing something obvious. If I try to convert a type to jsonschema with a narrow function it fails every time, even if I use the .in property. ```ts...

extracting redux-like actions from type.enumerated discriminated union

Trying unsuccessfully to convert some redux/reducer-like "action" object types to arktype: ```ts type TestAction1 = { type: 'ACTION_1', value: number } type TestAction2 = { type: 'ACTION_2', name: string}...

alternative to nesting quotes in quotes for strings?

```ts const Target = type("'BODY' | 'FACE' | 'ARMS'") const Entity = type({ targets: Target.array()...

template literal/backtick string types e.g. type T = `type-${string}`

I can't see how to do in Ark:
type UserId = `user-${string}`
type UserId = `user-${string}`
...

Multiple versions

Everytime I do some action with npm in my project, I get reinstalled two versions of arktype which break the project, this is the package.json part:
"arktype": "2.0.0-rc.5",
"arktype": "2.0.0-rc.5",
...
No description

Compile-time typesafe merge/and for data-only "traits"

I've evaluating introducing arktype to a typescript codebase, but I got stuck trying to use it to set up my POJO "traits" system. This is similar in concept to the Trait abstract class in arktype/util but this is data only; so far I've avoided the need to introduce any classes and I'm hoping to maintain this approach. So I have a discriminated union that represents the different "traits" and the union members share a common shape (mainly references to other trait names), something along these lines: ```ts...

Creating default object from type definition

Hi! I would like to migrate my project from TypeBox to ArkType, as I love the work you're doing on it, and the development experience seems much better. There is one feature that I love in TypeBox, but couldn't find in ArkType: creating a default object from a type definition. Is this something that exists or was ever raised/considered? I would find this feature very useful to create the initial state of a form, without any code duplication. Example syntax: ```ts...

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"})...