Primitives

string

A full list of string keywords can be found here.

literals

const  = ({
	singleQuoted: "'typescript'",
	doubleQuoted: '"arktype"'
})

patterns

Regex literals specify an unanchored regular expression that an input string must match.

They can either be string-embedded or refer directly to a RegExp instance.

const  = ({
	stringEmbedded: "/^a.*z$/",
	regexLiteral: /^a.*z$/
})

lengths

Constrain a string with an inclusive or exclusive min or max length.

const  = ({
	nonEmpty: "string > 0",
	atLeastLength3: "string.alphanumeric >= 3",
	lessThanLength10: "string < 10",
	atMostLength5: "string <= 5"
})

Range expressions allow you to specify both a min and max length and use the same syntax for exclusivity.

const  = ({
	nonEmptyAtMostLength10: "0 < string <= 10",
	integerStringWith2To5Digits: "2 <= string.integer < 6"
})

number

A full list of number keywords can be found here.

literals

const  = ({
	number: "1337"
})

ranges

Constrain a number with an inclusive or exclusive min or max.

const  = ({
	positive: "number > 0",
	atLeast3: "number.integer >= 3",
	lessThanPi: "number < 3.14159",
	atMost5: "number <= 5"
})

Range expressions allow you to specify both a min and max and use the same syntax for exclusivity.

const  = ({
	positiveAtMostE: "0 < number <= 2.71828",
	evenNumberAbsoluteValueLessThan50: "-50 < (number % 2) < 50"
})

divisors

Constrain a number to a multiple of the specified integer.

const  = ({
	key: "number % 2"
})

bigint

To allow any bigint value, use the "bigint" keyword.

const  = ({
	foo: "bigint"
})

literals

To require an exact bigint value in your type, you can use add the suffix n to a string-embedded number literal to make it a bigint.

const  = ({
	bigint: "1337n"
})

You may also use a unit expression to define bigint literals.

symbol

To allow any symbol value, use the "symbol" keyword.

const  = ({
	key: "symbol"
})

To reference a specific symbol in your definition, use a unit expression.

No special syntax is required to define symbolic properties like { [mySymbol]: "string" }. For more information and examples of how to combine symbolic keys with other syntax like optionality, see properties.

boolean

To allow true or false, use the "boolean" keyword.

const  = ({
	key: "boolean"
})

literals

To require a specific boolean value, use the corresponding literal.

const  = ({
	a: "true",
	b: "false",
	// equivalent to the "boolean" keyword
	c: "true | false"
})

null

The "null" keyword can be used to allow the exact value null, generally as part of a union.

const  = ({
	requiredKey: "number | null"
})

undefined

The "undefined" keyword can be used to allow the exact value undefined, generally as part of a union.

const  = ({
	requiredKey: "number | undefined"
})

Allowing undefined as a value does not make the key optional!

In TypeScript, a required property that allows undefined must still be present for the type to be satisfied.

The same is true in ArkType.

See an example
const  = ({
	key: "number | undefined"
})

// valid data
const  = myObj({ key: undefined })

// Error: name must be a number or undefined (was missing)
const  = myObj({})

On this page