Skip to content

Commit 0e1ac03

Browse files
committed
feat: improve type safety in EnumItemLabel
1 parent 0162986 commit 0e1ac03

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
# enum-plus Changelog
44

5+
## Unreleased
6+
7+
2025-10-??
8+
9+
### Features
10+
11+
- ✨ Allow extending `EnumItemLabel` type for better type safety and IntelliSense support.
12+
513
## 3.0.1
614

715
2025-10-6

src/extension.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ declare module 'enum-plus/extension' {
1616
*
1717
* **CN:** 枚举本地化的全局扩展
1818
*/
19+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
1920
interface EnumLocaleExtends {
2021
/**
2122
* **EN:** Key values of the localized text of the enumeration, which can be used to enhance the
2223
* intelligent prompt of the editor
2324
*
2425
* **CN:** 枚举本地化文本的Key值,可以用来增强编辑器的智能提示
2526
*/
26-
LocaleKeys: never;
27+
// LocaleKeys: NonNullable<string>;
2728
}
2829
}

src/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { EnumLocaleExtends } from 'enum-plus/extension';
22

33
export type { LocalizeInterface } from './localize-interface';
44

5+
// @ts-expect-error: because LocaleKeys is a user-defined type, so ignore the error here
56
export type EnumItemLabel = EnumLocaleExtends['LocaleKeys'] | NonNullable<string>;
67

78
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -53,11 +54,13 @@ export interface StandardEnumItemInit<V extends EnumValue> {
5354
}
5455
export interface ValueOnlyEnumItemInit<V extends EnumValue> {
5556
value: V;
57+
label?: never;
5658
}
5759
export interface LabelOnlyEnumItemInit {
5860
label: EnumItemLabel;
61+
value?: never;
5962
}
60-
export type CompactEnumItemInit = Record<string, never>; // 等价于{}
63+
export type CompactEnumItemInit = Record<string, never>; // equivalent to {}
6164

6265
/**
6366
* - **EN:** Data structure of enumeration item options, used in `toList` method

0 commit comments

Comments
 (0)