Announcing ArkType 2.2
Type-safe regex, validated functions, and native Standard Schema definitions
As of today, 2.2.0 is generally available 🎉
2.2 brings type.fn for runtime-validated functions, type-safe regex via arkregex, bidirectional JSON Schema with the new @ark/json-schema package, and universal schema interop- embed Zod, Valibot, or any Standard Schema validator directly in your definitions.
For the first time, the type safety ArkType brings to data can extend to your entire function boundary- parameters in, return value out, validated and introspectable. Regex literals now carry full type inference including capture groups. And with configurable toJsonSchema and @ark/json-schema, ArkType speaks JSON Schema in both directions.
Below are the full notes for the 2.2.0 release. We can't wait to hear what you think! 🚀
type.fn - Validated functions
Define functions with runtime-validated parameters and return types, all using the same syntax you already know. The result is a callable with .expression, .params, and .returns for introspection.
Since the types are defined as values rather than annotations, type.fn also works in plain .js files- no JSDoc or TypeScript required to get fully typed, validated function signatures.
Supports all the tuple features you'd expect- defaults, optionals, variadics:
Type-safe regex
ArkType 2.2 integrates arkregex, a type-safe wrapper for new RegExp(). Regex literals in your definitions now carry full type inference:
e(x)ec mode
Prefix a regex literal with x to parse capture groups at runtime, fully typed via arkregex:
For the standalone package (no ArkType required), see the full arkregex announcement.
@ark/json-schema - Bidirectional JSON Schema
The new @ark/json-schema package allows you to parse JSON Schema directly into ArkType Types, complementing the existing toJsonSchema() method on every Type. Together, they provide full bidirectional conversion.
Special thanks to @TizzySaurus for the incredible work on this package 🙌
Configurable toJsonSchema
Some ArkType features don't have JSON Schema equivalents. By default, toJsonSchema() throws in these cases. The new fallback config lets you handle incompatibilities granularly:
toJsonSchema() now also accepts a target option and can generate draft-07 in addition to the default draft-2020-12. Cyclic types are fully supported and generate $ref-based schemas.
ArkType also implements the Standard JSON Schema interface, so libraries that consume Standard Schema can access JSON Schema directly via the ~standard property.
Full documentation including the complete table of fallback codes is available in the configuration docs.
Standard Schema as definitions
Any Standard Schema compliant validator can now be passed directly to type, either at the top level or nested inside a structural definition, and will be fully inferred and validated.
This makes ArkType a universal composition layer- mix and match validators from any ecosystem in a single definition.
select - Deep reference introspection
The new select method lets you query the internal structure of a type. Every Type is built from a tree of nodes (domains, constraints, morphs, etc.), and select extracts references by kind and predicate:
These selectors can also be used to target specific references for configuration, avoiding the need to transform the entire type:
Improved type.declare
type.declare now supports morph-aware declarations via a side context, and optionality can be expressed via property values in addition to keys:
If your type includes morphs like string.numeric.parse, you can declare just the input side or the output side. This is useful when your external type represents one half of a transformation:
When there's a mismatch, you get a clear error showing exactly what went wrong:
Serializable ArkErrors
ArkErrors are now JSON stringifiable, making it easy to send validation errors as API responses or store them in logs. Two new properties provide structured access:
Unhandled validation errors now throw a TraversalError (instead of AggregateError) with cleaner multi-error formatting (thanks @LukeAbby).
N-ary operators
type.or, type.and, type.merge, and type.pipe are standalone functions that accept variadic definitions, avoiding the need to chain or compose binary expressions:
String-embeddable |> pipe operator
The to operator (|>) can now be used directly inside string definitions:
type.valueOf
Create a Type from a TypeScript enum or enum-like object:
New keywords
Two new built-in string keywords:
exactOptionalPropertyTypes config
ArkType now supports a global config for exactOptionalPropertyTypes, matching TypeScript's compiler option:
Additional improvements
Type#distribute: Map and optionally reduce over union branches e.g.T.distribute(branch => branch.expression). See Type API docs.- ES2020 / Hermes compatibility: Removed usages of newer prototype methods like
.at()to support legacy browsers and React Native's Hermes engine - In-docs playground: Try ArkType directly from the docs at arktype.io/playground with full type checking and formatting
- Cyclic unions can now discriminate on nested paths, improving performance and error messages for complex recursive types
- Faster shallow completions: Near-instant autocomplete for
type("") - Better JSDoc and go-to-definition for parsed object keys
- Improved
.expressionfor regex constraints: Now displays/^pattern$/instead ofstring /^pattern$/ - Generic descriptions are now included for built-in generics like
Record,Pick,Omit,Partial,Required,Exclude,Extract, andMerge toJsonSchema()format annotations: Built-in string keywords likestring.email,string.ip.v4,string.ip.v6,string.url, andstring.uuidnow emit proper JSON Schemaformatfields, improving OpenAPI compatibility- Duplicate key detection: Definitions with conflicting keys like
{ foo: "string", foo?: "string" }now throw a descriptive error at parse time - Unsatisfiable index signature intersections now result in a
ParseErrorinstead of silently producing an unusable type - Fixed predicate errors after the first not being reported for multi-property constraints
- Fixed clone crash when an object has a getter or setter as a non-prototype property
- Fixed custom
messagecallbacks in JIT mode that previously produced"$ark.message"instead of the expected string - Fixed morph inference for environments where global prototypes like
FormDataresolve to{}(e.g.@types/bun) - Fixed metatype extraction from recursive definitions where
DefaultandOutwere not properly inferred
⭐ Check out the project on GitHub
👋 Join our Discord to lurk or ask questions
-
Follow any of these accounts for updates:
- @arktype.io, @ssalbdivad.dev on BlueSky
- @arktypeio, @ssalbdivad on X/Twitter
-
Consider supporting my full-time work on ArkType...
- via GitHub Sponsors
- by convincing your team to let me optimize your types and fix editor lag (reach out directly to one of the accounts listed or
david@arktype.io)