Skip to content

Configuration

Errors

🚧 Coming soon ™️🚧

Clone

By default, before a morph is applied, ArkType will deeply clone the original input value with a built-in deepClone function that tries to make reasonable assumptions about preserving prototypes etc. The implementation of deepClone can be found here.

You can provide an alternate clone implementation to the clone config option.

import { configure } from "arktype/config"

configure({ clone: structuredClone })

import { type } from "arktype"

// will now create a new object using structuredClone
const 
const userForm: Type<{
    age: (In: string) => To<number>;
}>
userForm
= type({
age: "string.numeric.parse" })

To mutate the input object directly, you can set the clone config option to false.

import { configure } from "arktype/config"

configure({ clone: false })

import { type } from "arktype"

const 
const userForm: Type<{
    age: (In: string) => To<number>;
}>
userForm
= type({
age: "string.numeric.parse" }) const
const formData: {
    age: string;
}
formData
= {
age: "42" } const
const out: ArkErrors | {
    age: number;
}
out
= userForm(
const formData: {
    age: string;
}
formData
)
// the original object's age key is now a number console.log(
const formData: {
    age: string;
}
formData
.age)

onUndeclaredKey

🚧 Coming soon ™️🚧

jitless

By default, when a Type is instantiated, ArkType will precompile optimized validation logic that will run when the type is invoked. This behavior is disabled by default in environments that don’t support new Function, e.g. Cloudlflare Workers.

If you’d like to opt out of it for another reason, you can set the jitless config option to true.

import { configure } from "arktype/config"

// IMPORTANT: make sure you import from the "arktype/config" entry point
// and invoke configure before importing anything else from ArkType
// unless you want the builtin types to be precompiled

configure({ jitless: true })

import { type } from "arktype"

// will not be precompiled
const 
const myObject: Type<{
    foo: string;
}>
myObject
= type({
foo: "string" })