EnumInfo

View source

ExtendsTypeInfo

Describes the named numeric variants in enum reflection metadata.

EnumInfo stores each variant name with its numeric discriminant. It is reflection metadata only: it does not hold an enum value or enforce how a runtime value uses the discriminants. Its serialized form is an object with kind: 'enum' and a variants record.

Examples

const info = new EnumInfo({ Idle: 0, Running: 1 })
info.get('Running') // 1
info.serialize() // { kind: 'enum', variants: { Idle: 0, Running: 1 } }

Constructor


constructor(variants: Record<string, number>)

View source

Creates enum reflection metadata from variant names and discriminants.

The record is copied into a new map; later changes to the record do not change this metadata. EnumInfo has no default factory, so provide the complete variant record when constructing it.

Parameters

NameDescriptionDefault
variants——

Properties


Methods


get(variant: string): number

View source

Returns the numeric discriminant for a variant name.

Parameters

NameDescriptionDefault
variant——

Returns

The discriminant, or undefined when the variant is not registered.

getVariants(): Iterable<string, any, any>

View source

Returns an iterator over variant names in metadata order.

[iterator](): MapIterator<[string, number]>

View source

Iterates over [variant, discriminant] pairs in metadata order.

serialize(): EnumInfoSerial

View source

Serializes this metadata as an enum kind with a plain variant record.

The serial contains exactly { kind: 'enum', variants }, where each variant name maps to its numeric discriminant.

staticserialize(value: EnumInfo): EnumInfoSerial

View source

Serializes enum metadata without mutating the source instance.

variants is converted from the internal map to a plain object. For example, new EnumInfo({ Idle: 0, Running: 1 }).serialize() returns { kind: 'enum', variants: { Idle: 0, Running: 1 } }.

Parameters

NameDescriptionDefault
value——

staticdeserialize(value: EnumInfoSerial, out?: EnumInfo): EnumInfo

View source

Restores enum metadata from a serialized variant record.

Without out, this creates a new instance. With out, it clears the existing variant map, copies the serialized entries in order, and returns the same instance. The serial is assumed to have been validated first.

Parameters

NameDescriptionDefault
value——
out?—...

staticvalidateSerial(value: unknown): value is EnumInfoSerial

View source

Checks whether a value has the serialized enum metadata shape.

Validation requires a non-null, non-array object with kind: 'enum' and a non-null, non-array variants object whose values are all numbers. Extra properties are allowed; this method validates the serial shape and does not create an EnumInfo.

Parameters

NameDescriptionDefault
value——