gpt4 book ai didi

javascript - slim typescript 上的 slim 自定义事件

转载 作者:行者123 更新时间:2023-12-05 00:24:36 27 4
gpt4 key购买 nike

我在我的 svelte-typescript 项目上使用 clickOutside 指令,当我将自定义事件分配给相关元素时出现此错误

Type '{ class: string; onclick_outside: () => boolean; }' is not assignable to type 'HTMLProps<HTMLDivElement>'.
Property 'onclick_outside' does not exist on type 'HTMLProps<HTMLDivElement>'
这是我的代码片段
{#if profileToolbar}
<div
transition:fly={{ y: -20, duration: 300 }}
use:clickOutside={profileToolbarContainer}
on:click_outside={() => (profileToolbar = !profileToolbar)}
class="origin-top-right absolute right-0 mt-2 w-48 rounded-md
shadow-lg z-10 shadow-md">
这是我当前使用的 clickOutside 指令 https://svelte.dev/repl/0ace7a508bd843b798ae599940a91783?version=3.16.7
我是 typescript 的新手,所以我真的不知道从哪里开始我的谷歌搜索,有人知道如何解决这个问题吗?感谢您的帮助

最佳答案

根据doc ,您可以创建一个.d.ts文件在你的项目某处。并在该文件中放入以下内容:

declare namespace svelte.JSX {
interface HTMLAttributes<T> {
onclick_outside: () => void
}
}
请阅读文档以获取更多详细信息。

关于javascript - slim typescript 上的 slim 自定义事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64131176/

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