arktype

A

arktype

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

Join

ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options

Hello! When key isn't provided in the .map function, the above error is thrown. Not working code: ```ts...

Dynamic type based on another value

Given a theoretical example like this: ```ts const formDef = type({ agree: 'boolean',...

Why does an optional property add a " | undefined" instead of just being an optional property?

Hi, this feels like such a basic question that it probably has an answer, but I don't understand why marking a arktype property as optional not just makes the corresponding inferred type property optional, without adding an additional | undefined? I encountered something similar with zod which had the result that my zod-type and database generated type did not match although they should. Dummy example: ```ts const schema = type({...

Generic with Narrow/Morph

I want to make something like ```ts type UniqueArray<T, K extends keyof T> ...

Extracting defaults at runtime

Hello! What is the canon way to extract the default values of the type on runtime? I'd like to uuse the defaults from the type as defaults in a form. ```ts...

Ark attest cannot find module error

Hello! In a pnpm monorepo, with @ark/attest installed in the workspace root and running pnpx run attest trace ., I get the following output: ```...

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)...
Next