From bb99345f5b3074febe6d261dc29110bc00b29f01 Mon Sep 17 00:00:00 2001 From: kyyy <60952577+rdjanuar@users.noreply.github.com> Date: Thu, 17 Jul 2025 02:58:05 +0700 Subject: [PATCH] fix(RadioGroup): improve type safety for normalizeItem function (#4535) Co-authored-by: Sandro Circi --- src/runtime/components/RadioGroup.vue | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/runtime/components/RadioGroup.vue b/src/runtime/components/RadioGroup.vue index 3a07201f..bfd5e0b5 100644 --- a/src/runtime/components/RadioGroup.vue +++ b/src/runtime/components/RadioGroup.vue @@ -70,7 +70,9 @@ export type RadioGroupEmits = RadioGroupRootEmits & { change: [payload: Event] } -type SlotProps = (props: { item: T & { id: string }, modelValue?: RadioGroupValue }) => any +type NormalizeItem = Exclude + +type SlotProps = (props: { item: NormalizeItem, modelValue?: RadioGroupValue }) => any export interface RadioGroupSlots { legend(props?: {}): any @@ -114,21 +116,21 @@ const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.radioGroup | indicator: props.indicator })) -function normalizeItem(item: any) { +function normalizeItem(item: T): NormalizeItem { if (item === null) { return { id: `${id}:null`, value: undefined, label: undefined - } + } as NormalizeItem } - if (typeof item === 'string' || typeof item === 'number') { + if (typeof item === 'string' || typeof item === 'number' || typeof item === 'bigint') { return { id: `${id}:${item}`, value: String(item), label: String(item) - } + } as NormalizeItem } const value = get(item, props.valueKey as string) @@ -136,7 +138,7 @@ function normalizeItem(item: any) { const description = get(item, props.descriptionKey as string) return { - ...item, + ...(item as NormalizeItem), value, label, description,