@@ -171,59 +171,44 @@ export interface IEnumItems<
171171 has ( keyOrValue ?: string | V ) : boolean ;
172172
173173 /**
174- * **EN:** Generate an array of objects that can be bound to those `options like` of components
175- * such as Select, Radio, and Checkbox, following the data specification of ant-design
174+ * **EN:** Generate an object array containing all enumeration items
176175 *
177- * **CN:** 生成一个对象数组,可以绑定到 Select、Radio、Checkbox 等组件的`options`,遵循 ant-design 的数据规范
176+ * **CN:** 生成一个对象数组,包含所有的枚举项
178177 *
179178 * @example
180179 * [
181180 * { value: 0, label: 'Sunday' },
182181 * { value: 1, label: 'Monday' },
183182 * ];
184- *
185- * @see https://ant.design/components/checkbox-cn#option
186183 */
187- // eslint-disable-next-line @typescript-eslint/method-signature-style
188- toList ( ) : EnumItemOptionData < K , V > [ ] ;
184+ toList ( ) : EnumListItem < 'label' , 'value' > [ ] ;
189185 /**
190- * **EN:** Generate an array of objects that can be bound to those `options like` of components
191- * such as Select, Radio, and Checkbox, following the data specification of ant-design
186+ * **EN:** Generate an object array containing all enumeration items, with customizable value and
187+ * label field names
192188 *
193- * **CN:** 生成一个对象数组,可以绑定到 Select、Radio、Checkbox 等组件的`options`,遵循 ant-design 的数据规范
189+ * **CN:** 生成一个对象数组,包含所有的枚举项,可自定义值和标签字段名
194190 *
195191 * @example
196192 * [
197193 * { value: 0, label: 'Sunday' },
198194 * { value: 1, label: 'Monday' },
199195 * ];
200196 *
201- * @param config Custom options | 自定义选项
202- *
203- * @see https://ant.design/components/checkbox-cn#option
197+ * @param config Custom options, supports customizing value and label field names |
198+ * 自定义选项,支持自定义值和标签字段名
204199 */
205- // eslint-disable-next-line @typescript-eslint/method-signature-style
206- toList ( config : ToListConfig & BooleanFirstOptionConfig < V > ) : EnumItemOptionData < K | '' , V | '' > [ ] ;
207- /**
208- * **EN:** Generate an array of objects that can be bound to those `options like` of components
209- * such as Select, Radio, and Checkbox, following the data specification of ant-design
210- *
211- * **CN:** 生成一个对象数组,可以绑定到 Select、Radio、Checkbox 等组件的`options`,遵循 ant-design 的数据规范
212- *
213- * @example
214- * [
215- * { value: 0, label: 'Sunday' },
216- * { value: 1, label: 'Monday' },
217- * ];
218- *
219- * @param config Custom options | 自定义选项
220- *
221- * @see https://ant.design/components/checkbox-cn#option
222- */
223- // eslint-disable-next-line @typescript-eslint/method-signature-style
224- toList < FK , FV > (
225- config : ToListConfig & ObjectFirstOptionConfig < FK , FV >
226- ) : EnumItemOptionData < K | ( FK extends never ? FV : FK ) , V | ( FV extends never ? V : FV ) > [ ] ;
200+ toList <
201+ OV extends string | ( ( item : EnumItemClass < T [ K ] , K , V > ) => string ) = string ,
202+ OL extends string | ( ( item : EnumItemClass < T [ K ] , K , V > ) => string ) = string ,
203+ > (
204+ config : ToListConfig < T , OL , OV , K , V >
205+ ) : EnumListItem <
206+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
207+ OL extends ( ...args : any ) => any ? ReturnType < OL > : OL ,
208+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
209+ OV extends ( ...args : any ) => any ? ReturnType < OV > : OV ,
210+ V
211+ > [ ] ;
227212
228213 /**
229214 * **EN:** Generate an object array that can be bound to the data source of components such as
@@ -415,15 +400,13 @@ export interface LabelOnlyEnumItemInit {
415400}
416401export type CompactEnumItemInit = Record < string , never > ; // 等价于{}
417402
418- /** Data structure of ant-design Select options */
419- export interface EnumItemOptionData < K , V > {
420- /** Option value */
421- value : V ;
422- /** Option label */
423- label : string ;
424- /** Option key, default is `value` */
425- key : K ;
426- }
403+ /**
404+ * **EN:** Data structure of enumeration item options, used in `toList` method
405+ *
406+ * **CN:** 枚举项选项的数据结构,用于`toList`方法
407+ */
408+ export type EnumListItem < FL extends string = string , FV extends string = string , V = EnumValue > = Record < FV , V > &
409+ Record < FL , string > ;
427410
428411/** Data structure of column filter items of ant-design Table */
429412export interface ColumnFilterItem < V > {
@@ -453,6 +436,8 @@ export type EnumKey<T> = keyof T;
453436/** More options for the options method */
454437export interface ToListConfig <
455438 T extends EnumInit < K , V > ,
439+ OV extends string | ( ( item : EnumItemClass < T [ K ] , K , V > ) => string ) = string ,
440+ OL extends string | ( ( item : EnumItemClass < T [ K ] , K , V > ) => string ) = string ,
456441 K extends EnumKey < T > = EnumKey < T > ,
457442 V extends EnumValue = ValueTypeFromSingleInit < T [ K ] , K > ,
458443> {
@@ -462,73 +447,16 @@ export interface ToListConfig<
462447 *
463448 * **CN:** 输出对象的value字段名,或者获取字段名的函数,默认为 `value`
464449 */
465- valueField ?: string | ( ( item : EnumItemClass < T [ K ] , K , V > [ ] ) => string ) ;
450+ valueField ?: OV ;
466451 /**
467452 * **EN:** The name of the label field in the output object, or a function to get the field name,
468453 * default is `label`
469454 *
470455 * **CN:** 输出对象的label字段名,或者获取字段名的函数,默认为 `label`
471456 */
472- labelField ?: string | ( ( item : EnumItemClass < T [ K ] , K , V > [ ] ) => string ) ;
457+ labelField ?: OL ;
473458}
474459
475- export interface BooleanFirstOptionConfig < V > {
476- /**
477- * **EN:** Add a default option at the top
478- *
479- * - `true`: the option uses the default value, `value` is `''`, `label` is `'All'`;
480- * - `false`: the default option is not added;
481- *
482- * **CN:** 在头部添加一个默认选项
483- *
484- * - `true`:选项使用默认值,`value`为`''`,`label`为`'全部'`
485- * - `false`:不添加默认选项
486- *
487- * @default false
488- */
489- firstOption : boolean ;
490- /**
491- * **EN:** Default option value, default is `''`
492- *
493- * **CN:** 默认选项的值,默认为`''`
494- *
495- * @default ''
496- */
497- firstOptionValue ?: V ;
498- /**
499- * **EN:** Default option label, default is `'All'`. If a localization method is set, the
500- * localization method will be automatically called
501- *
502- * **CN:** 默认选项的显示文本,默认为`'All'`。如果设置了本地化方法,则会自动调用本地化方法
503- */
504- firstOptionLabel ?: string ;
505- }
506-
507- export interface ObjectFirstOptionConfig < K , V > {
508- /**
509- * **EN:** Configuration of the first option
510- *
511- * **CN:** 首行选项的配置
512- */
513- firstOption ?: EnumOptionConfig < K , V > ;
514- /**
515- * **EN:** Add a default option at the top
516- *
517- * **CN:** 默认选项的值,默认为`''`
518- */
519- firstOptionValue ?: never ;
520- /**
521- * **EN:** Default option label, default is `'All'`. If a localization method is set, the
522- * localization method will be automatically called
523- *
524- * **CN:** 默认选项的显示文本,默认为`'All'`。如果设置了本地化方法,则会自动调用本地化方法
525- */
526- firstOptionLabel ?: never ;
527- }
528-
529- export type EnumOptionConfig < K , V > = Omit < EnumItemOptionData < K , V > , 'key' > &
530- Partial < Pick < EnumItemOptionData < K , V > , 'key' > > ;
531-
532460/** Infer the value type from the initialization object of the enumeration item */
533461export type ValueTypeFromSingleInit < T , Key = string , Fallback = Key > = T extends EnumValue // literal类型
534462 ? T
0 commit comments