arktype

A

arktype

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

Join

Wrapper around `type()`

In my configuration loader that I'm building, I have a "registry" pattern where I want to have developers declare the type schema of the config they expect, and then they need to register the config in order to get it loaded, looks something like this: ```ts const GoodConfig = registerConfig( 'GoodConfig', type({...

Runtime coercion

I'm building a system to load declarative runtime configuration from a couple different sources, all of which provide values as strings (env vars, AWS SSM Parameters). Currently I'm walking through the typeJson at runtime to build accessors for each field, such as joining field names with __ to build environment variable keys, and that is working great. I can cleanly detect when I reach a "leaf" type to load, and I either have a string or an object with a "domain"; my challenge is whether there is an elegant way of coercing the string I load into the type expected at this point (without making some huge imperative logic block). I'm hopeful there might be some clever thing under the hood that I can use in place of rolling my own....

Mapping types

Hello, is it possible do to code like this? ```ts const x = type({ a: 'string', b: 'string',...

How to improve error messages?

address must be a string and less than length 200 and more than length 50 and valid according to an anonymous predicate and valid according to an anonymous predicate and valid according to an anonymous predicate (was missing)
This is an example of a validation error message returned. How could I go about making that a little more human friendly?...

Pipe required before narrow

const myFunc = (v: string) => true;
const MyString = type("50<string<200").narrow((s) => myFunc(s));
const myFunc = (v: string) => true;
const MyString = type("50<string<200").narrow((s) => myFunc(s));
Results in error:...

Error transforming object

I'm having some trouble doing transforming some data

Problem with Out type

Type '(In: string) => Out<bigint>' is not assignable to type 'bigint'
Type '(In: string) => Out<bigint>' is not assignable to type 'bigint'

Problem with validation in 2.0 dev?

I'm using 2.0.0-dev.11 and cannot figure out why some very basic validation fails. Short example: ```ts import { type } from "arktype"; ...

out.summary returns only one error 2.0.0-dev.11

Hi, I am just wondering if I am using this correctly as I followed the new arktype tutorial I made the following schema and validated it However, it only gives me one error...

Referencing self

Hello, I have a type A ```ts const A = { hello: 'string', aArray: arrayOf(???)...

Export type to JSON and share it

Hello, I have two TS programs that should cooperate (A B), B import types and validates data, and A creates and "saves" the types. A rough idea ```ts // Program A import { type } from 'arktype' ...

False recursive reference

Anyone know how I can get past this false positive claiming I'm recursively referencing process.env in its base type? Since the value is just being used to compute the base type, not in the actual base type, this should be okay. ``` import { type } from "arktype"; ...

How to specify a property of type function?

In Typescript I have defined it like this: ```ts type User = { accounts: accounts?: (() => Promise<Account>)[]; }...

Why scope().compile().infer resolves to any?

I tried to follow the example here: https://arktype.io/docs/scopes Not sure if this is a bug or if I'm doing it wrong Stackblitz: https://stackblitz.com/edit/rzkceh-eodur9?file=demo.ts%3AL63,index.ts...

How to Union in scope()?

Union 1 will be resolved as I would expect to ts?: string | TimeStub | undefined;: ```ts export const myType = type({ "id?": "string",...

How to include an external class into an arktype type?

I tried ```ts import { TimeStub } from 'fauna'; // class const clientDocument = type({...

Are you recommending to create first ArkType types and derive from their TS types or vice versa?

Are you recommending to create first ArkType types and derive from their TS types or vice versa?

Array error message

Hello, I think I found an inconsistency in array errors: https://stackblitz.com/edit/vy55da?file=type.ts The tags error is: tags must be at least 3 characters (was 2) But should probably not be characters, but something like items....

Unions with optional params?

Are unions with optional params supported in arktype? Example: ```typescript import { type, union } from "arktype"...

ParseError: '3.0' was parsed as a number but could not be narrowed to a literal value.

I'm not sure yet, where does this come from, but does it say anything to you? ``` /projects/custom/hfl/node_modules/arktype/dist/cjs/utils/errors.js:25 throw new ParseError(message); ^...