所有有关‘数据录入’和 ‘数据展示’的组件都需支持泛型
guaijie opened this issue · 0 comments
guaijie commented
- I have searched the issues of this repository and believe that this is not a duplicate.
What problem does this feature solve?
缺乏泛型支持的组件失去了类型推断的能力:
import { Select } from 'ant-design-vue'
const model = reactive({ sex: 1 })
const sexRef = ref<number>()
<Select options={options} v-model:value={model.sex} onChange={(v) => sexRef.value = v} />
// model.sex 是一个 number 类型,onChange 事件中可以推断出 v 应该是个 number 类型,而非内置的 SelectValue 类型,这将使得 sexRef.value 赋值报错。因此项目中会存在大量的类型转换问题
What does the proposed API look like?
有关‘数据录入’和 ‘数据展示’的组件都应该支持泛型
type SelectProps<T> = {
value?: T,
//...
}
// 使用 defineComponent
defineComponent(<T,>(props: SelectProps<T>) => {
}, {
name: 'ASelect',
props: getSelectProps()
})
// setup
<script setup lang="tsx" generic="T extends object">
const props = defineProps<SelectProps<T>>()
</script>