enum-plus
Version:
A drop-in replacement for native enum. Like native enum but much better!
59 lines (58 loc) • 1.97 kB
TypeScript
import type { EnumItemInit, EnumItemOptions, EnumKey, EnumValue, ValueTypeFromSingleInit } from './types';
import { ENUM_ITEM } from './utils';
/**
* Enum item class
*
* @template V General type for item value
* @template K General type for item key
* @template T General type for item initialization object
*/
export declare class EnumItemClass<T extends EnumItemInit<V>, K extends EnumKey<any> = string, V extends EnumValue = ValueTypeFromSingleInit<T, K>> {
#private;
/**
* **EN:** The value of the enum item
*
* **CN:** 枚举项的值
*/
readonly value: V;
/**
* **EN:** The label of the enum item (also known as display name)
*
* **CN:** 枚举项的标签(亦称显示名称)
*/
readonly label: string;
/**
* **EN:** The key of the enum item, which is the key in the initialization object when creating
* the enum collection.
*
* **CN:** 枚举项的键,即创建枚举集合时初始化对象中的键
*/
readonly key: K;
/**
* **EN:** The original initialization object of the enum item, which is the sub-object of a
* single enum item when creating the enum collection.
*
* **CN:** 枚举项的原始初始化对象,即创建枚举集合时单个枚举项的子对象
*/
readonly raw: T;
/**
* **EN:** A boolean value indicates that this is an enum item instance.
*
* **CN:** 布尔值,表示这是一个枚举项实例
*/
readonly [ENUM_ITEM] = true;
/**
* Instantiate an enum item
*
* @param key Enum item key
* @param value Enum item value
* @param label Enum item display name
* @param raw Original initialization object
* @param options Construction options
*/
constructor(key: K, value: V, label: string, raw: T, options?: EnumItemOptions);
readonly(): this;
toString(): any;
toLocaleString(): any;
valueOf(): V;
}