vue3在使用element plus中
ts 参数类型推断与回调函数的问题
回调参数问题,怎么才能消掉这个报错。
你可以看看以下几种方法:
const handleCallback = (data: string) => {
// 处理回调函数的逻辑
};
handleCallback('some data'); // 传递的参数是 string 类型
defineProps
或 PropType
来明确指定回调函数的参数类型。import { defineProps, PropType } from 'vue';
const YourComponent = {
props: {
callback: {
type: Function as PropType<(data: string) => void>,
required: true,
},
},
// ...
};
handleOpen(key, keyPath) {
console.log(key, keyPath);
},
handleClose(key, keyPath) {
console.log(key, keyPath);
}
我想解决的是 ts 参数类型推断与回调函数隐式传递参数 不匹配的问题