Skip to content

Literals

Literals offer string-embedded syntax for specifying exact values, paralleling TypeScript where applicable.

String

const 
const literals: Type<{
    singleQuoted: "typescript";
    doubleQuoted: "arktype";
}>
literals
=
const type: TypeParser
<{
    readonly singleQuoted: "'typescript'";
    readonly doubleQuoted: "\"arktype\"";
}, Type<{
    singleQuoted: "typescript";
    doubleQuoted: "arktype";
}, {}>>(def: validateObjectLiteral<{
    readonly singleQuoted: "'typescript'";
    readonly doubleQuoted: "\"arktype\"";
}, {}, bindThis<...>>) => Type<...> (+2 overloads)
type
({
singleQuoted: "'typescript'", doubleQuoted: '"arktype"' })

Number

const 
const literals: Type<{
    number: 1337;
}>
literals
=
const type: TypeParser
<{
    readonly number: "1337";
}, Type<{
    number: 1337;
}, {}>>(def: validateObjectLiteral<{
    readonly number: "1337";
}, {}, bindThis<{
    readonly number: "1337";
}>>) => Type<...> (+2 overloads)
type
({
number: "1337" })

Bigint

const 
const literals: Type<{
    bigint: 1337n;
}>
literals
=
const type: TypeParser
<{
    readonly bigint: "1337n";
}, Type<{
    bigint: 1337n;
}, {}>>(def: validateObjectLiteral<{
    readonly bigint: "1337n";
}, {}, bindThis<{
    readonly bigint: "1337n";
}>>) => Type<...> (+2 overloads)
type
({
bigint: "1337n" })

Date

Date literals represent a Date instance with an exact value.

They’re primarily useful in ranges.

const 
const literals: Type<{
    singleQuoted: Date.nominal<"01-01-1970">;
    doubleQuoted: Date.nominal<"01-01-1970">;
}>
literals
=
const type: TypeParser
<{
    readonly singleQuoted: "d'01-01-1970'";
    readonly doubleQuoted: "d\"01-01-1970\"";
}, Type<{
    singleQuoted: Date.nominal<"01-01-1970">;
    doubleQuoted: Date.nominal<"01-01-1970">;
}, {}>>(def: validateObjectLiteral<...>) => Type<...> (+2 overloads)
type
({
singleQuoted: "d'01-01-1970'", doubleQuoted: 'd"01-01-1970"' })

Regex

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 
const literals: Type<{
    stringEmbedded: string.matching<"^a.*z$">;
    regexLiteral: string.matching<string>;
}>
literals
=
const type: TypeParser
<{
    readonly stringEmbedded: "/^a.*z$/";
    readonly regexLiteral: RegExp;
}, Type<{
    stringEmbedded: string.matching<"^a.*z$">;
    regexLiteral: string.matching<string>;
}, {}>>(def: validateObjectLiteral<...>) => Type<...> (+2 overloads)
type
({
stringEmbedded: "/^a.*z$/", regexLiteral: /^a.*z$/ })