hashbrown

enumeration

Creates a string enumeration schema.

Pass an array of entries, or a record mapping each entry to a description of what it means. The JSON Schema stays provider-safe: it emits a plain enum, and the entry descriptions are appended to the description as a - key: description list.

API

export declare function enumeration<const Entries extends readonly string[]>(
  description: string,
  entries: [...Entries],
):  EnumType <Entries>;
enumeration
EnumType<Entries>
@paramdescription:
string

Description of the enumeration.

@paramentries:
[...Entries]

The allowed values, or a record of value to description.

@typeEntries
readonly string[]
@returns
EnumType<Entries>

API

export declare function enumeration<const Entry extends string>(
  description: string,
  entries:  Record <Entry, string>,
):  EnumType <Entry[]>;
enumeration
EnumType<Entry[]>
@paramdescription:
string

Description of the enumeration.

@paramentries:
Record<Entry, string>

A record mapping each allowed value to its description.

@typeEntry
string
@returns
EnumType<Entry[]>

Examples

const kind = s.enumeration('Kind', { jet: 'Jets', rotor: 'Helicopters' });