From 123d2c9074b8dd1a5cef7476d22d95ba835ae885 Mon Sep 17 00:00:00 2001 From: WgoW <139880996+WgoW@users.noreply.github.com> Date: Wed, 23 Apr 2025 21:34:06 +0800 Subject: [PATCH] feat(types): enhance Option type to support customizable label types (#735) Co-authored-by: a --- src/typings/common.d.ts | 2 +- src/utils/common.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/typings/common.d.ts b/src/typings/common.d.ts index 06b526c9..652bc3bc 100644 --- a/src/typings/common.d.ts +++ b/src/typings/common.d.ts @@ -14,7 +14,7 @@ declare namespace CommonType { * @property value: The option value * @property label: The option label */ - type Option = { value: K; label: string }; + type Option = { value: K; label: M }; type YesOrNo = 'Y' | 'N'; diff --git a/src/utils/common.ts b/src/utils/common.ts index dc9a368f..b7e7f654 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -22,7 +22,7 @@ export function transformRecordToOption>(record return Object.entries(record).map(([value, label]) => ({ value, label - })) as CommonType.Option[]; + })) as CommonType.Option[]; } /** @@ -30,10 +30,10 @@ export function transformRecordToOption>(record * * @param options */ -export function translateOptions(options: CommonType.Option[]) { +export function translateOptions(options: CommonType.Option[]) { return options.map(option => ({ ...option, - label: $t(option.label as App.I18n.I18nKey) + label: $t(option.label) })); }