arktype

A

arktype

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

Join

CJS/ESM issue with arktype

I installed arktype. It's a ESM thing, and it broke my building process. To fix it, I had to switch to building with babel and had to set these values in tsconfig.json:: ``` "module": "ES2015", "moduleResolution": "Bundler"...

The inferred type of '... cannot be named without a reference to '../../../../node_modules/arktype/

I receive this strange message:
src/clients/client-amazon.ts:76:3 - error TS2742: The inferred type of 'get' cannot be named without a reference to '../../../../node_modules/arktype/dist/types/scopes/type'. This is likely not portable. A type annotation is necessary.
src/clients/client-amazon.ts:76:3 - error TS2742: The inferred type of 'get' cannot be named without a reference to '../../../../node_modules/arktype/dist/types/scopes/type'. This is likely not portable. A type annotation is necessary.
...

Need help with typing scope output properly

I've got one crazy idea to declare types as scopes to access validators independently

non-empty string - how to?

How to declare a schema with 'string' type but... not empty, i.e. which is banning ""?

How to incorporate existing type?

I have a type imported from a third-party API and I'd like to build it in into my ark type: ```ts import { Foo } from 'fancy-api' const schema = type({...

How to declare an optional schema?

I wonder if it's possible to define a schema that is ok if data is undefined. E.g. in: ```ts declare function foo(a?: string)v void...

Can scopes validate?

Can scopes validate or they are only a collection of types?

How to properly make a property of a class type?

I tried this: ```ts class TokenManager {} const params = type({ tokenManager: type(['instanceof', TokenManager]),...

Utility to make Partials?

Is there a way to get a type that is Partial<> from another type?

default values - how to define them?

I only found an issue by David that it's gonna be implemented, but I cannot find any examples.

Using existing enum/const to build a type

Hi folks. I'm very new to arktype so maybe I'm asking something very simple. I have a pseudo enum in a third-party module I import. This const is defined as: ...

How to import `arktype` into a typescript project?

I do it like this:
import { type } from 'arktype';
import { type } from 'arktype';
...

Context-sensitive validation / validation with parameters

```ts interface Thing { bars: string[]; foo: { baz: { bar: string }[]; }[]; }...

Validate string is URL

What would be the easiest way to validate that the url in here is an actual valid url? ```ts const button = type({ label: "2<=string<=32", url: "2<=string<=512",...

How to validate that a value is an instance of a class

Is there a way (yet) to validate that a value is an instance of a class? I know this doesn't work, but maybe it'll convey the idea: ```typescript class SomeClass {}...

Array/Object keys to type?

So I got this object: ```ts export const supportedLanguages: { afr: Language; ara: Language;...

Nesting ArkTypes within a regex

Is there a way to put ArkType types within a regex? As an example
const x = type("0<string<3");
const y = type("0<number<10");
const z = type("/x y/");
const x = type("0<string<3");
const y = type("0<number<10");
const z = type("/x y/");
where for z something like hi 3 would be valid, but not hi 13 or hello 5 -- i.e. to be valid, the value passed into z has to be a string of length 1 or 2, followed by a space, followed by a number 1-9 (inclusive))...

Custom type-making functions

I want to make a chainable that can create types the same way type does How do I implement that? ```ts thing // Thing<never, never> .input('number%1>0') // Thing<number, never>...

Syntax Overview

Someone was asking for an overview of available syntax. I ended up coming this and figured it would be useful to post it here. It doesn't include everything (notably most tuple expressions and scopes), but it's a good place to start: ```ts...
No description