在开发应用的过程中,在前端,我遇到了一个奇怪的onClick函数问题,如下
Type '(e: SyntheticEvent<Element, Event>) => void' is not assignable to type 'CustomValueType | MotionValue<number> | MotionValue<string> | MotionValue<any> | ((event: MouseEvent<{}, MouseEvent>) => void)'.
Type '(e: SyntheticEvent<Element, Event>) => void' is not assignable to type '(event: MouseEvent<{}, MouseEvent>) => void'.
Types of parameters 'e' and 'event' are incompatible.
Type 'MouseEvent<{}, MouseEvent>' is not assignable to type 'SyntheticEvent<Element, Event>'
这些是出现此错误的 onClick 函数
onClick={(e: SyntheticEvent) => {
setDeleteAddOptions(!deleteAddOptions),
e.stopPropagation();
}}
onClick={(e: SyntheticEvent) => e.stopPropagation()}
也许是类型定义问题?我能做些什么来解决它?
感谢您的时间!
答案 0 :(得分:1)
正如错误所说。您正在尝试将一种合成事件类型分配给需要 MouseEvent 的组件。只需将 SyntheticEvent 换成 MouseEvent 就可以了。