Defjs
Core

struct.literal

Struct that accepts exactly one boolean, null, number, or string value.

@defjs/core · Function

Signature

function literal<const T extends LiteralValue>(
  value: T,
): Struct<T, T>;
  • Accepts only value. The comparison uses Object.is, so any other value fails with invalid_literal.

  • value must be a boolean, null, number, or string.

  • Use it for the tag field of struct.discriminatedUnion().

Parameters

Prop

Type

value T
Edit this page on GitHub
Released under the MIT License. · Copyright © 2026 MunMunMiao