feat(types): enhance Option type to support customizable label types (#735)
Co-authored-by: a <a@gmail.com>
This commit is contained in:
parent
05dc11e258
commit
123d2c9074
2
src/typings/common.d.ts
vendored
2
src/typings/common.d.ts
vendored
@ -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';
|
||||
|
||||
|
@ -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)
|
||||
}));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user