feat(types): enhance Option type to support customizable label types (#735)

Co-authored-by: a <a@gmail.com>
This commit is contained in:
WgoW 2025-04-23 21:34:06 +08:00 committed by GitHub
parent 05dc11e258
commit 123d2c9074
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -14,7 +14,7 @@ declare namespace CommonType {
* @property value: The option value * @property value: The option value
* @property label: The option label * @property label: The option label
*/ */
type Option<K = string> = { value: K; label: string }; type Option<K = string, M = string> = { value: K; label: M };
type YesOrNo = 'Y' | 'N'; type YesOrNo = 'Y' | 'N';

View File

@ -22,7 +22,7 @@ export function transformRecordToOption<T extends Record<string, string>>(record
return Object.entries(record).map(([value, label]) => ({ return Object.entries(record).map(([value, label]) => ({
value, value,
label label
})) as CommonType.Option<keyof T>[]; })) as CommonType.Option<keyof T, T[keyof T]>[];
} }
/** /**
@ -30,10 +30,10 @@ export function transformRecordToOption<T extends Record<string, string>>(record
* *
* @param options * @param options
*/ */
export function translateOptions(options: CommonType.Option<string>[]) { export function translateOptions(options: CommonType.Option<string, App.I18n.I18nKey>[]) {
return options.map(option => ({ return options.map(option => ({
...option, ...option,
label: $t(option.label as App.I18n.I18nKey) label: $t(option.label)
})); }));
} }