11import { internalConfig , localizer } from './global-config' ;
2- import type { EnumItemInit , EnumKey , EnumValue , LocalizeInterface , ValueTypeFromSingleInit } from './types' ;
2+ import type {
3+ EnumItemInit ,
4+ EnumItemLabel ,
5+ EnumKey ,
6+ EnumValue ,
7+ LocalizeInterface ,
8+ ValueTypeFromSingleInit ,
9+ } from './types' ;
310import { IS_ENUM_ITEM } from './utils' ;
411
512/**
@@ -20,7 +27,7 @@ export class EnumItemClass<
2027 const P = any ,
2128> {
2229 private _options : EnumItemOptions < T , K , V , P > | undefined ;
23- private _label : string | undefined ;
30+ private _label : EnumItemLabel | undefined ;
2431 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2532 private _localize : ( content : string | undefined ) => any ;
2633
@@ -34,10 +41,10 @@ export class EnumItemClass<
3441 * @param raw The original initialization object | 原始初始化对象
3542 * @param options Optional settings for the enum item | 枚举项的可选设置
3643 */
37- constructor ( key : K , value : V , label : string , raw : T , options ?: EnumItemOptions < T , K , V , P > ) {
44+ constructor ( key : K , value : V , label : EnumItemLabel , raw : T , options ?: EnumItemOptions < T , K , V , P > ) {
3845 this . key = key ;
3946 this . value = value ;
40- this . label = label ;
47+ this . label = label as string ;
4148 this . raw = raw ;
4249
4350 // Should use _label instead of label closure, to make sure it can be serialized correctly
@@ -62,6 +69,10 @@ export class EnumItemClass<
6269 const labelPrefix = this . _options ?. labelPrefix ;
6370 const autoLabel = this . _options ?. autoLabel ?? internalConfig . autoLabel ;
6471 let localeKey = this . _label ;
72+ if ( typeof localeKey === 'function' ) {
73+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
74+ return localeKey ( this as any ) ;
75+ }
6576 if ( autoLabel && labelPrefix != null ) {
6677 if ( typeof autoLabel === 'function' ) {
6778 localeKey = autoLabel ( {
0 commit comments