Skip to content

Commit bb99345

Browse files
rdjanuarsandros94
andauthored
fix(RadioGroup): improve type safety for normalizeItem function (#4535)
Co-authored-by: Sandro Circi <sandro.circi@digitoolmedia.com>
1 parent c64c4cd commit bb99345

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

‎src/runtime/components/RadioGroup.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ export type RadioGroupEmits = RadioGroupRootEmits & {
7070
change: [payload: Event]
7171
}
7272
73-
type SlotProps<T extends RadioGroupItem> = (props: { item: T & { id: string }, modelValue?: RadioGroupValue }) => any
73+
type NormalizeItem<T extends RadioGroupItem> = Exclude<T & { id: string }, RadioGroupValue>
74+
75+
type SlotProps<T extends RadioGroupItem> = (props: { item: NormalizeItem<T>, modelValue?: RadioGroupValue }) => any
7476
7577
export interface RadioGroupSlots<T extends RadioGroupItem = RadioGroupItem> {
7678
legend(props?: {}): any
@@ -114,29 +116,29 @@ const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.radioGroup |
114116
indicator: props.indicator
115117
}))
116118
117-
function normalizeItem(item: any) {
119+
function normalizeItem(item: T): NormalizeItem<T> {
118120
if (item === null) {
119121
return {
120122
id: `${id}:null`,
121123
value: undefined,
122124
label: undefined
123-
}
125+
} as NormalizeItem<T>
124126
}
125127
126-
if (typeof item === 'string' || typeof item === 'number') {
128+
if (typeof item === 'string' || typeof item === 'number' || typeof item === 'bigint') {
127129
return {
128130
id: `${id}:${item}`,
129131
value: String(item),
130132
label: String(item)
131-
}
133+
} as NormalizeItem<T>
132134
}
133135
134136
const value = get(item, props.valueKey as string)
135137
const label = get(item, props.labelKey as string)
136138
const description = get(item, props.descriptionKey as string)
137139
138140
return {
139-
...item,
141+
...(item as NormalizeItem<T>),
140142
value,
141143
label,
142144
description,

0 commit comments

Comments
 (0)