问题
vue3+ts,使用PropType对props的数据做验证,与interface定义的数据没有对应上,但是却没有报错,FilterListProps
中并没有定义aaa
interface
interface OptionsProps {
value: string
label: string | number
}
interface FilterListProps {
type: string
title: string
placeholder: string
key: string
value: string
options?: OptionsProps[]
}
数据
filterList: [
{
type: 'input',
title: '用户ID',
placeholder: '请输入用户ID',
key: 'userId',
value: '',
aaa: ''
},
{
type: 'select',
title: '账号类型',
placeholder: '请选择',
key: 'accountType',
value: '',
options: [
{
value: '选项1',
label: '黄金糕'
},
{
value: '选项2',
label: '双皮奶'
}
]
},
]
PropType
props: {
filterList: {
type: Array as PropType<FilterListProps[]>,
// type: Array,
required: true
}
},
interface只会检查他是否是目标数据的子集,如果要明确的指定能出现的key可以这样做