Reputation: 276
but the code is doing the job with no error on chrome console
constructor() {
window.onclick = (event: MouseEvent) => {
if (!event.target.matches('.dropbtn')) {
const dropdowns = document.getElementsByClassName('dropdown-content');
let i;
for (i = 0; i < dropdowns.length; i++) {
const openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
};
}
something with typescript i assume.. anyone had it?
Upvotes: 2
Views: 541
Reputation: 10313
change the events type for a quick fix:
window.onclick = (event: any) => {
You could also use type assertions to tell the compiler that it is ok:
window.onclick = (event: MouseEvent) => {
const event_cast_type = event as any;
if (!event_cast_type.target.matches('.dropbtn')) {
But remember type assertions are as dangerous as using any since you are telling the compiler you know more about types than it does. However for this case I think it is the only way to pass this issue since a type assertion will kill the problem at its root which is the compiler.
Upvotes: 2