Comprehensive collection of built-in type validators including primitives, utility types, and specialized validators.
Core JavaScript/TypeScript primitive types.
// Basic primitives
const bigint: Type<bigint>;
const boolean: Type<boolean>;
const number: Type<number>;
const string: Type<string>;
const symbol: Type<symbol>;
const object: Type<object>;
const unknown: Type<unknown>;
// Literal values
const null: Type<null>;
const undefined: Type<undefined>;
const true: Type<true>;
const false: Type<false>;
const never: Type<never>;Usage Examples:
import { type } from "arktype";
// Direct usage
const isString = type("string");
const isNumber = type("number");
// In object definitions
const Config = type({
name: "string",
port: "number",
enabled: "boolean",
metadata: "object"
});Built-in generic utilities that mirror TypeScript's utility types.
/**
* Create object type with index signature
*/
const Record: <K extends Key, V>(K: Type<K>, V: Type<V>) => Type<Record<K, V>>;
/**
* Pick specific properties from object type
*/
const Pick: <T extends object, K extends keyof T>(
T: Type<T>,
K: Type<K>
) => Type<Pick<T, K>>;
/**
* Omit specific properties from object type
*/
const Omit: <T extends object, K extends keyof T>(
T: Type<T>,
K: Type<K>
) => Type<Omit<T, K>>;
/**
* Make all properties optional
*/
const Partial: <T extends object>(T: Type<T>) => Type<Partial<T>>;
/**
* Make all properties required
*/
const Required: <T extends object>(T: Type<T>) => Type<Required<T>>;
/**
* Exclude union members
*/
const Exclude: <T, U>(T: Type<T>, U: Type<U>) => Type<Exclude<T, U>>;
/**
* Extract union members
*/
const Extract: <T, U>(T: Type<T>, U: Type<U>) => Type<Extract<T, U>>;Usage Examples:
// Record type (use keywords)
const StringRecord = keywords.Record("string", "number");
// Type<Record<string, number>>
// Pick properties
const User = type({
id: "string",
name: "string",
email: "string",
age: "number"
});
const UserSummary = keywords.Pick(User, ["name", "email"]);
// Type<{ name: string; email: string }>
// Make optional
const PartialUser = keywords.Partial(User);
// Type<{ id?: string; name?: string; email?: string; age?: number }>
// Union manipulation
const StringOrNumber = type("string | number");
const OnlyString = keywords.Extract(StringOrNumber, "string");
// Type<string>Additional utility types and validators.
/**
* Valid object key type (string | number | symbol)
*/
const Key: Type<string | number | symbol>;
/**
* Merge object types with property precedence
*/
const Merge: <Base extends object, Props extends object>(
base: Type<Base>,
props: Type<Props>
) => Type<merge<Base, Props>>;
/**
* JSON-serializable values
*/
const json: {
root: Type<Json>;
stringify: Type<(In: Json) => To<string>>;
};Usage Examples:
// Key validation
const ValidKey = type("Key"); // string | number | symbol
// Object merging
const BaseUser = type({
id: "string",
name: "string"
});
const UserWithEmail = type.Merge(BaseUser, type({
email: "string",
name: "string" // overwrites base name
}));
// Type<{ id: string; name: string; email: string }>Specialized number types with constraints.
const number: {
root: Type<number>;
/** Integer numbers only */
integer: Type<number>;
/** Numbers in safe integer range */
safe: Type<number>;
/** Unix timestamp range (-8,640,000,000,000,000 to 8,640,000,000,000,000) */
epoch: Type<number>;
/** NaN value */
NaN: Type<number>;
/** Positive infinity */
Infinity: Type<number>;
/** Negative infinity */
NegativeInfinity: Type<number>;
};Usage Examples:
// Integer validation
const Age = type("number.integer > 0");
const SafeId = type("number.safe");
// Timestamp validation
const Timestamp = type("number.epoch");
// Special number values
const NotANumber = type("number.NaN");
const PositiveInf = type("number.Infinity");Basic string validation and format checking.
const string: {
root: Type<string>;
/** Letters only (a-z, A-Z) */
alpha: Type<string>;
/** Letters and digits (a-z, A-Z, 0-9) */
alphanumeric: Type<string>;
/** Digits only (0-9) */
digits: Type<string>;
/** Hexadecimal characters (0-9, a-f, A-F) */
hex: Type<string>;
/** Email address format */
email: Type<string>;
/** Valid URL format */
url: Type<string>;
/** UUID format (all versions) */
uuid: Type<string>;
/** IP address (v4 or v6) */
ip: Type<string>;
/** Credit card number with Luhn validation */
creditCard: Type<string>;
/** Semantic version format */
semver: Type<string>;
/** Valid regex pattern */
regex: Type<string>;
};Usage Examples:
// Basic patterns
const Username = type("string.alphanumeric");
const HexColor = type("string.hex");
// Format validation
const Email = type("string.email");
const Website = type("string.url");
const Id = type("string.uuid");
// In object types
const UserProfile = type({
username: "string.alphanumeric",
email: "string.email",
website: "string.url"
});Built-in constructor and collection types.
// JavaScript built-in constructors
const Array: Type<any[]>;
const Date: Type<Date>;
const RegExp: Type<RegExp>;
const Error: Type<Error>;
const Map: Type<Map<any, any>>;
const Set: Type<Set<any>>;
const WeakMap: Type<WeakMap<object, any>>;
const WeakSet: Type<WeakSet<object>>;
// Specialized object types
const json: {
root: Type<Json>; // JSON-serializable object
stringify: Type<(In: Json) => To<string>>;
};Usage Examples:
// Array validation
const StringArray = type("string[]");
const DateArray = type("Date[]");
// Built-in types
const UserDate = type("Date");
const Matcher = type("RegExp");
// JSON validation
const ApiPayload = type({
data: "json",
timestamp: "Date"
});Built-in constraint operators for validation.
// Comparison operators
type ComparisonOps = "<" | "<=" | ">" | ">=" | "==";
// Range constraints (for numbers/strings)
"number > 0" // Greater than 0
"number >= 18" // 18 or greater
"string < 100" // Length less than 100
"string <= 50" // Length 50 or less
// Divisibility
"number % 2" // Even numbers
"number % 3 == 1" // Numbers with remainder 1 when divided by 3
// Pattern matching
"/^[a-z]+$/" // Regex pattern
"'literal' | 'values'" // Exact literal unionUsage Examples:
// Age validation
const Adult = type("number.integer >= 18");
// String length
const Username = type("string >= 3 <= 20");
// Even numbers
const EvenNumber = type("number.integer % 2");
// Password pattern
const Password = type("string >= 8 & /^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)/");
// Status literals
const Status = type("'pending' | 'approved' | 'rejected'");