FAQ
Answers to common questions about ArkType's behavior, configuration and TypeScript integration.
Why do I see type errors in an ArkType package in node_modules?
This can occur due to incompatibilities between your tsconfig.json and ours. It is harmless as long as your types are correct in source.
We recommend enabling skipLibCheck in every TypeScript project to avoid false positives like this and improve editor performance.
Why does number reject Infinity?
number excludes NaN, Infinity and -Infinity by default, so validated numbers are finite. JSON can't represent them either: JSON.stringify(Infinity) is "null". To allow them in one type, add the corresponding keyword:
const const Bound: Type<number>Bound = type("number | number.Infinity | number.NegativeInfinity")To allow them everywhere, configure numberAllowsInfinity or numberAllowsNaN (see Configuration).
Why can't I index ArkErrors like an array?
ArkErrors isn't an Array. Its errors are in issues, one for each check that failed:
const const out: {
name: string;
} | ArkErrors
out = type({ name: "string" })({})
if (const out: {
name: string;
} | ArkErrors
out instanceof type.errors) {
// the error at name
const out: ArkErrorsout.issues[0]
// ["must be a string (was missing)"]
const out: ArkErrorsout.issues.map(e => e.message)
for (const const error: ArkError<ArkErrorCode>error of const out: ArkErrorsout.issues) console.log(const error: ArkError<ArkErrorCode>error.path)
}See Errors for everything an error carries.
Why does my error say must be Enter a valid email?
A string passed to .describe(), ctx.mustBe() or ctx.error(), or configured as expected, is what the value must be, so ArkType writes "must be" before it. A whole sentence is a message, which .message() sets, and which ctx.reject() takes as { message } (it doesn't take a string):
const const Email: Type<string>Email = type("string.email").message("Enter a valid email")
const const Deadline: Type<Date>Deadline = type("Date").narrow(
(d, ctx) => d > new Date() || ctx.reject({ message: "Choose a future date" })
)Why does my optional key reject undefined?
An optional key may be missing, but a key that's present must hold a value its definition allows, as with TypeScript's exactOptionalPropertyTypes. Add | undefined to the value, or set exactOptionalPropertyTypes: false to accept undefined at every optional key, as Zod does.
Why isn't my configuration applied?
Global config is fixed when the first Type is created, by a definition or by reading a keyword like type.number. Calling configure after that throws a ParseError: configure() must be called before any Type is created, so import the module calling it before any module that creates one (first Type created: ...), naming that first Type to help find the import order issue. Put it in its own file. See Configuration.
Why does Jest say Must use import to load ES Module?
ArkType ships ES modules only, and Jest runs tests as CommonJS, so a test that imports arktype fails, naming node_modules/arktype/out/index.js. Have Jest transform it, with a transform that reads JavaScript, like ts-jest's js-with-ts preset:
module.exports = {
preset: "ts-jest/presets/js-with-ts",
// arktype ships ES modules only
transformIgnorePatterns: ["/node_modules/(?!(\\.pnpm|arktype)/)"]
}\\.pnpm is for pnpm's layout, where each package is under node_modules/.pnpm. On Node 24.9 or later, a Jest that can require an ES module, like 30.5, needs no transform: run it with NODE_OPTIONS=--experimental-vm-modules.
Does a morph change my input?
Only if you mutate it, or configure mutatesInput. A morph receives the validated value itself, not a copy, so mutating its argument mutates the caller's data. Return a new value instead:
const const addTag: Type<(In: {
tags: string[];
}) => Out<{
tags: string[];
}>>
addTag = type({ tags: "string[]" }).pipe(o => ({
...o,
tags: [...o.tags, "new"]
}))Should I precompile?
If your app is bundled, yes. A precompiled build ships each Type as a standalone validator, without arktype's parser and without generating code at runtime, and your definitions don't change. Stay dynamic where there's no build step or a program composes Types at runtime. See Dynamic vs Precompiled.
How do I ship the types of my Types?
If a package or a referenced project exports types derived from arktype, write its declarations with ark declare rather than tsc:
npx arktype declareIt declares each Type by the shape it infers, so code importing the package reads that shape rather than inferring your definitions again. It needs no bundler and leaves your Types dynamic.
For a cyclic scope, it's required: TypeScript can't write an inferred cycle in a .d.ts, so tsc declares it as any or fails with TS5088, where ark declare names each cycle for its alias.
Can I get error messages in another language?
Yes. ArkType ships English and German, and you can write a locale for any other language. See i18n.
How does ArkType compare to Zod or Valibot?
All three validate at runtime, infer TypeScript types and implement Standard Schema, so a library that accepts one accepts the others. ArkType writes a definition in TypeScript's own syntax, where Zod and Valibot use function calls:
// z.object({ name: z.string(), age: z.number().int().min(0).optional() })
const const User: Type<{
name: string;
age?: number;
}>
User = type({
name: "string",
"age?": "number.integer >= 0"
})Precompiled, it ships no parser. Precompiled ArkType was faster than Zod 4 in all 32 scenarios of our benchmark, by a median of 15×, and faster than Zod 4's z.compile in 32 of 32, by a median of 5.3×. On Valibot's own login form, ArkType's default build reports an error for every invalid field, with the form's messages, in a smaller bundle than Valibot: 0.92 kB gzipped against 1.56 kB. Benchmarks has how each was measured.
Without the plugin, arktype parses definitions at runtime, so it ships its parser. Dynamic ArkType is 98.1 kB gzipped, minified with esbuild, up from 47.8 kB in 2.2.9, so precompile to ship less.
Migrating maps Zod's API and Valibot's row by row, and has a prompt that migrates a project for you. You can also adopt ArkType one schema at a time.
Why isn't my wrapper generic working?
TypeScript's generic inference has many edge cases. General patterns for wrapping Types and definitions are outlined in the Generics docs.
infoType-level logic needs a cast
When implementing a function with a generic return type, you will almost always need to cast in your implementation, either explicitly via as or by using an overload.
Think of it as trading internal safety for external precision. As long as the function you're writing will be called many times externally, the overhead is justified. If not, it may not need to be generic at all. A broad return type like string as opposed to ${prefix}.${key} may be sufficient.
See an example
// via explicit cast
const createBox = <const def>(
of: type.type type<t = unknown, $ = {}>.validate<def, $ = {}, args = bindThis<def>> = [def] extends [" anyOrNever"] ? def : def extends OptionalPropertyDefinition ? "Optional definitions like 'string?' are only valid as properties in an object or tuple" : isDefaultable<def, $, args> extends true ? "Defaultable definitions like 'number = 0' are only valid as properties in an object or tuple" : validateInnerDefinition<def, $, args>validate<def>
): type.type type<t = unknown, $ = {}>.instantiate<def, $ = {}, args = bindThis<def>> = [inferDefinition<def, $, args>] extends [" anyOrNever"] ? Type<" anyOrNever" & inferDefinition<def, $, args>, $> : [inferDefinition<def, $, args>] extends [string] ? Type<string & inferDefinition<def, $, args>, $> : [inferDefinition<def, $, args>] extends [number] ? Type<number & inferDefinition<def, $, args>, $> : [...] extends [...] ? instantiateObjectType<...> : Type<...>instantiate<{ box: def }> =>
type.raw({
box: of
// when implementing generics, never is your go-to
// for allowing an arbitrary assignment with less risk than `any`
}) as never
// via overloads
// only the external signatures are considered on invocation
function createBox2<const def>(
of: type.type type<t = unknown, $ = {}>.validate<def, $ = {}, args = bindThis<def>> = [def] extends [" anyOrNever"] ? def : def extends OptionalPropertyDefinition ? "Optional definitions like 'string?' are only valid as properties in an object or tuple" : isDefaultable<def, $, args> extends true ? "Defaultable definitions like 'number = 0' are only valid as properties in an object or tuple" : validateInnerDefinition<def, $, args>validate<def>
): type.type type<t = unknown, $ = {}>.instantiate<def, $ = {}, args = bindThis<def>> = [inferDefinition<def, $, args>] extends [" anyOrNever"] ? Type<" anyOrNever" & inferDefinition<def, $, args>, $> : [inferDefinition<def, $, args>] extends [string] ? Type<string & inferDefinition<def, $, args>, $> : [inferDefinition<def, $, args>] extends [number] ? Type<number & inferDefinition<def, $, args>, $> : [...] extends [...] ? instantiateObjectType<...> : Type<...>instantiate<{ box: def }>
// the signature associated with the implementation is much looser and should
// be thought of as equivalent to casting in terms of type safety
function createBox2(of: unknown) {
return type.raw({
box: of
})
}
// Type<{ box: string }>
const const Box: Type<{
box: string;
}>
Box = createBox("string")In both cases, we've explicitly annotated the return type we want and used some method of casting internally to allow our implementation. This is a common pattern for implementing generic functions and, more generally, associating an implementation with typings TS can't infer on its own.
How a generic of your own infers depends on TypeScript rather than on ArkType's API. For anything these patterns don't cover, ask in our Discord.
What's up with your type/Type casing?
These docs use PascalCase for some Types and camelCase for others:
const const User: Type<{
name: string;
platform: "android" | "ios";
version?: string | number;
}>
User = type({
name: "string",
platform: "'android' | 'ios'",
"version?": "number | string"
})
const const parseJson: Type<(In: string) => To<{
name: string;
version: string;
}>>
parseJson = type("string.json.parse").to({
name: "string",
version: "string.semver"
})Types that only validate are named like TypeScript types. Types that transform their input behave like functions, so they're named like functions. Casing doesn't affect your Types or scope aliases, so use whatever rules suit your repo.
Is there a way to create an async morph?
No. A morph can return a promise as its output, but ArkType doesn't await it, so run async checks after validation. If you have a use case for more, add it to this GitHub issue.