Answer the question
In order to leave comments, you need to log in
How to cast event.target to type Node?
Hello, I have an event handler that calls a function that iterates over dom
window.addEventListener("click", (event: Event) => {
if (!this.checkParentsHas(event.target, this.$refs.nav))
this.isToggled = false;
});
checkParentsHas(el: Node, target: HTMLElement): boolean {
let current = el;
while (
current.parentNode != null &&
current.parentNode != document.documentElement
) {
if (current == target) {
return true;
} else {
current = current.parentNode;
}
}
return false;
},
Argument of type 'EventTarget' is not assignable to parameter of type 'Node'.
Type 'EventTarget' is missing the following properties from type 'Node': baseURI, childNodes, firstChild, isConnected, and 43 more.Vetur(2345)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question