Overview
Use Enum(...) when plain constants or native enum are not enough and the task needs labels, metadata, option lists, reverse lookup, or enum-aware typing. Prefer the standard object form in application code because it keeps UI text, metadata, and lookups in one place.
Workflow
- Pick one enum shape and keep it consistent for the whole enum.
- Prefer the standard
{ value, label, ...meta }form unless the task is intentionally simpler. - Use built-in enum methods before writing custom maps or switch statements.
- Read the matching reference file for deeper details.
Choose the Input Form
- Use key-value form for lightweight constant replacement.
- Use standard form for most app code, especially if the enum feeds UI or needs metadata.
- Use key-label form when
valueshould equalkey. - Use array form when the source data is dynamic or comes from an API.
- Use native-enum conversion only when the project already owns a native
enumand wants enum-plus behavior on top.
Read references/core-api.md for examples of each form.
Apply the Core Rules
- Do not mix initialization shapes inside one enum.
- Keep enum type names in
PascalCasewith anEnumsuffix. - Prefer enum member keys in
PascalCase. - Use
has,label,key,findBy,toList, andtoMapbefore writing custom helpers. - Store UI-adjacent metadata on enum items instead of scattering extra lookup tables.
- Validate untrusted values with
enum.has(value)before consuming them.
TypeScript Guidance
- If the codebase uses TypeScript below 5.0, add
as constto preserve literal values. - Use
typeof MyEnum.valueTypefor value unions andtypeof MyEnum.keyTypefor key unions. - Use
typeof MyEnum.rawTypewhen another API needs the initializer shape. - When adding global extensions, also add the matching
declare module 'enum-plus/extension'typing.
UI and Localization Guidance
- For component option lists, prefer
enum.itemsfirst. - Use
toListortoMaponly when the consumer expects custom field names or a different shape. @enum-plus/plugin-antdis already installed globally insrc/main.tsviaEnum.install(antdPlugins). Methods liketoSelect,toMenu,toFilter, andtoValueMapare available on all enums — no extra setup needed.- This project currently uses direct string labels (e.g. Chinese text) rather than i18n keys.
Enum.localizeis not wired and no i18n plugin is installed. Do not assume labels are localized. - If the task also changes Vue, antdv-next, or repo-specific UI code, load the matching repo skill alongside this one.
Read references/integration-patterns.md for concrete integration patterns.
Common Moves
- Replace
switch-based label lookup withenum.label(value). - Replace separate
optionsarrays withenum.itemsorenum.toList(...). - Replace ad hoc reverse maps with
enum.key(value)orenum.findBy(...). - Replace duplicated metadata tables with enum item
rawfields. - Convert an existing native
enumwithEnum(NativeEnum)when incremental migration is safer than a rewrite.
References
references/core-api.md: initializer formats, instance API, static API, config, and TS-only types.references/integration-patterns.md: UI binding, plugin usage, localization, conflicts, and best practices.
Constraints
- Do not claim plugin methods exist unless the plugin was installed.
- Do not assume
labelis localized unlessEnum.localizeor an i18n plugin is configured. - Do not hand-roll mutable edits against
enum.items; treat enum collections as read-only.