Inspector does not find currentTarget.className

已回答

This code:

document.querySelector(".editBackground.layer3").addEventListener("animationend", (event) =>
{
if (event.currentTarget.className.indexOf("fadeOut") !== -1)
document.querySelector(".editBackground.layer3").remove();
}, false);

creates a warning since the last days. I am pretty sure it didn't before as I have this code many times in my apps and always remove all warnings

"Unresolved variable className"

Why?

 

 

0

You will face similar error if you try to compile your code: TS2339: Property 'className' does not exist on type 'EventTarget'.

the reason is that the exact type of event is unknown, so the type is inferred as generic Event; EventTarget interface doesn't have className property. You need to explicitly tell the IDE the type of the HTMLElement which is your target using type annotations. See https://freshman.tech/snippets/typescript/fix-value-not-exist-eventtarget/

0

Hi Elena,

thanks for the answer. But I do not use typescript, so I need to fix this for javascript where I have no type casting. I till struggle why this dit not happen in the past. Is there something new in IntelliJ or may I have misconfigured anything?

 

 

1

In JavaScript, you can use JSDoc annotations to specify types explicitly

1

请先登录再写评论。