arktype

A

arktype

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

Join

Hi,

new to arktype, i have two questions: 1. i can't add a default for array ? like : foo:"string[]=['bar']" 2. given a type with all it's default can i create a concrete object from this type with all the default like: const foo=type({bar:"number.integer=42"}) and get back const defObj={bar: 42}...

How to ensure optimal discrimination of union types?

I have a union of types, each of which has an attribute with literal values that can in theory be used to quickly identify an appropriate top-level type. They all look like this: ```ts MyModelV1_0: { // model specific fields times: "number[]",...

Extract schema inside an array

Hello there, I'm new to ArkType, and I'm hitting an issue that I cannot seem to be able to solve... I'm trying to extract the runtime schema from within an array. Here is a simple example: ```typescript const simple = type({ id: 'number', array: type({...

exact length "string = 2"

Can we do something like stateCode: 'string.alpha = 2' ? stateCode: type.string.exactlyLength(2), works but curious if the = works...

Recursive types and d.ts files

I'm trying to define recursive types, where there's different kind of objects. One kind is a container, which can contain any kind of those objects, including other containers. My current approach looks like this: ```ts export const TestData = type.module({ objectData: "object | container",...
No description

TypeScript first - is possible or not? Can't remember :)

Hi folks! I'm not an ArkType regular as I would wish to be, so I may ask the same questions sometimes. Sorry for this. I wonder if it's possible to define TypeScript-first schema, and to pass the type as generic?...
No description

Can arktype drop data not covered by schema?

I want to regurgitate my input according to the schema model, e.g: ``` const user = type({ name: "string", })...

`.and` with default, expected behavior?

```typescript import { type } from "arktype"; const a = type({ someVal: type('string > 0')...

Filtering Array<unknown> to a type?

Is this the best way to filter an Array of unknown to an ark type?: ```ts type transaction = type(...); const items: unknown[] = ...;...

How can we describe a string with a length restriction?

e.g.:
type("5 < string.numeric < 7").describe("valid otp")
type("5 < string.numeric < 7").describe("valid otp")
...

Encountering "Uncaught SyntaxError: Identifier 'module' has already been declared"

I'm new to arktype and don't have a deep understanding of how web bundlers/etc work, so this may be a bit of a noob question. I'm using npm and parcel in our code base with several other package dependencies. The error above is referring to this line of code: ```...

Optional required pairs?

I have a type that has all optional properties. However I want to want to make 2 options a pair - if one exists, the other is required. An example: ```ts const props = type({...

Best way of sharing/compiling types?

I have two applications, in one I have defined types like ```ts const loginPayload = type({ email: email, password: "string", "+": "delete",...

Why are the partial operator `?` and explicit `undefined` incompatible?

I define the type: ```ts import { type } from 'arktype'; const checkType = type({...

Framework-level onDeepUndeclaredKey

Hi, thanks for this awesome library! I'm implementing arktype for my team and I plan on using it for DTOs which would validate the input and the output of our tRPC functions. For the output DTOs, I want to enforce the deletion of "deep undeclared keys" to make sure we don't leak any information, like this:...

email or empty string not working

export const feedbackSchema = type({
contact: 'string.email | string == 0'
});
export const feedbackSchema = type({
contact: 'string.email | string == 0'
});
...

Test that a string contains a substring?

Test that a string contains a substring?

Is there a recommended way to create a Record using a type as a key?

None of these seem to work: ```ts const stringKeys = type( "===", "CAR",...

`narrow` vs `satisfying`

I've ran across both functions, I can see the signatures are the same, but the type are not. I was wondering what the different is, between the two ?

Are there docs on how to do non-trivial self reference?

I can't seem to find them. I'm aware of the this keyword, but I'm looking to do something like: ```ts const example = type({ name: "string", selves: "this[]",...
Next