Enum Plus
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
value should equal key.
- 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
enum and 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
PascalCase with an Enum suffix.
- Prefer enum member keys in
PascalCase.
- Use
has, label, key, findBy, toList, and toMap before 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 const to preserve literal values.
- Use
typeof MyEnum.valueType for value unions and typeof MyEnum.keyType for key unions.
- Use
typeof MyEnum.rawType when 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.items first.
- Use
toList or toMap only when the consumer expects custom field names or a different shape.
@enum-plus/plugin-antd is already installed globally in src/main.ts via Enum.install(antdPlugins). Methods like toSelect, toMenu, toFilter, and toValueMap are available on all enums — no extra setup needed.
- This project currently uses direct string labels (e.g. Chinese text) rather than i18n keys.
Enum.localize is 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 with enum.label(value).
- Replace separate
options arrays with enum.items or enum.toList(...).
- Replace ad hoc reverse maps with
enum.key(value) or enum.findBy(...).
- Replace duplicated metadata tables with enum item
raw fields.
- Convert an existing native
enum with Enum(NativeEnum) when incremental migration is safer than a rewrite.
References
Constraints
- Do not claim plugin methods exist unless the plugin was installed.
- Do not assume
label is localized unless Enum.localize or an i18n plugin is configured.
- Do not hand-roll mutable edits against
enum.items; treat enum collections as read-only.
1---2name: enum-plus3description: Use when defining, migrating, validating, localizing, or rendering enum-plus enums in TypeScript or JavaScript code, including replacing native enums, adding labels or metadata, generating UI option data, installing enum-plus plugins, or narrowing values with enum-derived types.4---56# Enum Plus78## Overview910Use `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.1112## Workflow13141. Pick one enum shape and keep it consistent for the whole enum.152. Prefer the standard `{ value, label, ...meta }` form unless the task is intentionally simpler.163. Use built-in enum methods before writing custom maps or switch statements.174. Read the matching reference file for deeper details.1819## Choose the Input Form2021- Use key-value form for lightweight constant replacement.22- Use standard form for most app code, especially if the enum feeds UI or needs metadata.23- Use key-label form when `value` should equal `key`.24- Use array form when the source data is dynamic or comes from an API.25- Use native-enum conversion only when the project already owns a native `enum` and wants enum-plus behavior on top.2627Read [`references/core-api.md`](./references/core-api.md) for examples of each form.2829## Apply the Core Rules3031- Do not mix initialization shapes inside one enum.32- Keep enum type names in `PascalCase` with an `Enum` suffix.33- Prefer enum member keys in `PascalCase`.34- Use `has`, `label`, `key`, `findBy`, `toList`, and `toMap` before writing custom helpers.35- Store UI-adjacent metadata on enum items instead of scattering extra lookup tables.36- Validate untrusted values with `enum.has(value)` before consuming them.3738## TypeScript Guidance3940- If the codebase uses TypeScript below 5.0, add `as const` to preserve literal values.41- Use `typeof MyEnum.valueType` for value unions and `typeof MyEnum.keyType` for key unions.42- Use `typeof MyEnum.rawType` when another API needs the initializer shape.43- When adding global extensions, also add the matching `declare module 'enum-plus/extension'` typing.4445## UI and Localization Guidance4647- For component option lists, prefer `enum.items` first.48- Use `toList` or `toMap` only when the consumer expects custom field names or a different shape.49- `@enum-plus/plugin-antd` is already installed globally in `src/main.ts` via `Enum.install(antdPlugins)`. Methods like `toSelect`, `toMenu`, `toFilter`, and `toValueMap` are available on all enums — no extra setup needed.50- This project currently uses direct string labels (e.g. Chinese text) rather than i18n keys. `Enum.localize` is not wired and no i18n plugin is installed. Do not assume labels are localized.51- If the task also changes Vue, antdv-next, or repo-specific UI code, load the matching repo skill alongside this one.5253Read [`references/integration-patterns.md`](./references/integration-patterns.md) for concrete integration patterns.5455## Common Moves5657- Replace `switch`-based label lookup with `enum.label(value)`.58- Replace separate `options` arrays with `enum.items` or `enum.toList(...)`.59- Replace ad hoc reverse maps with `enum.key(value)` or `enum.findBy(...)`.60- Replace duplicated metadata tables with enum item `raw` fields.61- Convert an existing native `enum` with `Enum(NativeEnum)` when incremental migration is safer than a rewrite.6263## References6465- [`references/core-api.md`](./references/core-api.md): initializer formats, instance API, static API, config, and TS-only types.66- [`references/integration-patterns.md`](./references/integration-patterns.md): UI binding, plugin usage, localization, conflicts, and best practices.6768## Constraints6970- Do not claim plugin methods exist unless the plugin was installed.71- Do not assume `label` is localized unless `Enum.localize` or an i18n plugin is configured.72- Do not hand-roll mutable edits against `enum.items`; treat enum collections as read-only.