fix(InputMenu/Select/SelectMenu): improve types (#2471)

This commit is contained in:
Yasser Lahbibi
2024-10-28 18:08:24 +01:00
committed by GitHub
parent 1402436c2b
commit db8111d783
10 changed files with 226 additions and 38 deletions

View File

@@ -5,6 +5,7 @@ import ComponentRender from '../component-render'
import theme from '#build/ui/input'
import { renderForm } from '../utils/form'
import type { FormInputEvents } from '~/src/module'
import { expectEmitPayloadType } from '../utils/types'
describe('Select', () => {
const sizes = Object.keys(theme.variants.size) as any
@@ -166,5 +167,33 @@ describe('Select', () => {
await flushPromises()
expect(wrapper.text()).not.toContain('Error message')
})
test('should have the correct types', () => {
// with object item
expectEmitPayloadType('update:modelValue', () => Select({
items: [{ label: 'foo', value: 'bar' }]
})).toEqualTypeOf<[string]>()
// with string item
expectEmitPayloadType('update:modelValue', () => Select({
items: ['foo']
})).toEqualTypeOf<[string]>()
// with groups
expectEmitPayloadType('update:modelValue', () => Select({
items: [['foo']]
})).toEqualTypeOf<[string]>()
// with groups and mixed types
expectEmitPayloadType('update:modelValue', () => Select({
items: [['foo', { value: 1 }], [{ value: 'bar' }, 2]]
})).toEqualTypeOf<[string | number]>()
// with groups, mixed types and valueKey = undefined
expectEmitPayloadType('update:modelValue', () => Select({
items: [['foo', { value: 1 }], [{ value: 'bar' }, 2]],
valueKey: undefined
})).toEqualTypeOf<[string | number]>()
})
})
})