返回以下错误 Type '{ class: string; onmousewheel: (e: any) => void; }' is n-6ren">
gpt4 book ai didi

typescript - 鼠标滚轮功能在 svelte 上返回错误

转载 作者:行者123 更新时间:2023-12-05 02:01:45 25 4
gpt4 key购买 nike

我想知道为什么这段代码

<div class="home" on:mousewheel="{e=>handleScroll(e)}"></div>

返回以下错误

Type '{ class: string; onmousewheel: (e: any) => void; }' is not assignable to type 'HTMLProps'.Property 'onmousewheel' does not exist on type 'HTMLProps'.

这只是出于好奇,因为即使出现错误,它也能完美运行。

附言。我正在使用 TypeScript

最佳答案

鼠标滚轮事件是deprecated according to MDN并且不会在 Firefox 中工作。因为它是非标准的,所以不包含在 JSX typings 中由 Svelte 使用。

最好使用标准wheel event ,它取代了鼠标滚轮。如果真的要用事件,可以enhance the Svelte typings在一个单独的文件中:

// additional-svelte-jsx.d.ts
declare namespace svelte.JSX {
interface HTMLAttributes<T> {
onmousewheel?: (event: any) => any;
}
}

关于typescript - 鼠标滚轮功能在 svelte 上返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66354346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com