小编Dmi*_*sov的帖子

在 Vue 3 中侦听事件时,TypeScript 错误“Type '($event: any) => void' is not assignable to type'”

组件代码:

<h2 @click="handleEvent(post.id)">{{ post.title }}</h2>

function handleEvent(id: number) {
  router.push("/post/" + id);
}
Run Code Online (Sandbox Code Playgroud)

打字稿错误:

Type '($event: any) => void' is not assignable to type 'MouseEvent'.ts(2322)
__VLS_types.ts(107, 56): The expected type comes from property 'click' which is declared here on type 'EventObject<undefined, "click", {}, MouseEvent | undefined>'
Run Code Online (Sandbox Code Playgroud)

问题是什么?

typescript vue.js

16
推荐指数
2
解决办法
2797
查看次数

标签 统计

typescript ×1

vue.js ×1