如何解决将带有详细信息的自定义事件传递到TS中的事件处理程序
我想将鼠标事件与detail对象一起传递。我收到此错误:类型'never'不存在属性'detail'.ts(2339)
interface CustomEvent {
detail: {
left: number;
top: number;
radius: number;
label: string;
color: string;
};
}
export const Cursor: FC = () => {
const onCursorEvent = (event: MouseEvent | CustomEvent) => {
const newState = {}
if ('detail.radius' in event) {
newState.radius = event.detail.radius
}
setCursorState(newState)
}
const setSubscription = () => {
const cursor$ = fromEvent<MouseEvent>(document,'cursor')
const move$ = fromEvent<MouseEvent>(document,'mousemove').pipe(throttleTime(12))
const cursorEvents = merge(
cursor$,move$
)
cursorEvents.subscribe(event => onCursorEvent(event))
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。