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

This commit is contained in:
a 2025-04-17 22:29:35 +08:00
parent 8527aa80b8
commit 25788deb63
2 changed files with 4 additions and 4 deletions

View File

@ -14,7 +14,7 @@ declare namespace CommonType {
* @property value: The option value
* @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';

View File

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