Type annotations can only be used in TypeScript files.ts(8010)

huangapple go评论70阅读模式
英文:

Type annotations can only be used in TypeScript files.ts(8010)

问题

I'm getting error on React.MouseEvent<HTMLElement>

const handleOpenNavMenu = (event: React.MouseEvent<HTMLElement>) => {
    setAnchorElNav(event.currentTarget);
};
const handleOpenUserMenu = (event: React.MouseEvent<HTMLElement>) => {
    setAnchorElUser(event.currentTarget);
};
英文:

I'm getting error on React.MouseEvent&lt;HTMLElement&gt;

const handleOpenNavMenu = (event: React.MouseEvent&lt;HTMLElement&gt;) =&gt; {
    setAnchorElNav(event.currentTarget);
};
const handleOpenUserMenu = (event: React.MouseEvent&lt;HTMLElement&gt;) =&gt; {
    setAnchorElUser(event.currentTarget);
};

答案1

得分: 0

如果是 *.jsx 文件,只需删除:React.MouseEvent。这是 TypeScript 中的一种类型。

英文:

If it's a *.jsx file, just remove : React.MouseEvent<HTMLElement>. It's a type for typescript.

huangapple
  • 本文由 发表于 2023年5月14日 23:35:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76248313.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定