Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

232
Visualizações
Why is WebStorm not showing suggestions for anode.parentNode.classList? In fact it is underlining it as wrong

So I have noticed sometimes WebStorm does not show proper suggestions with JavaScript and even underlines valid code as wrong. In this case, the missed suggestion happens with this code:

document.addEventListener("DOMContentLoaded", () =\> {

    //Get form and required fields
    const form = document.querySelector("#mainForm");
    const required = document.querySelectorAll(".required");
    form.addEventListener('submit', validateForm);      //Add Listener to submit form
    
    function validateForm(e) {
        //Check if title is blank
        if (required[0].value === "" || required[0].value == null) {
            required[0].parentNode.classList.add("highlight");      //Add to parent
            required[0].classList.add("highlight");                 //Add to child 
            e.preventDefault();
        }
        //Check if checkbox is checked
        if (!required[2].checked || required[2].value == null) {
            required[2].parentNode.classList.add("highlight");     //Highlight parent (box)
            e.preventDefault();
        }
    }

});

The problem is in required[0].parentNode.classList.add("highlight") WebStorm underlines .classlist as wrong. In fact when I type required[0].parentNode. it does not suggest classList as an option. I checked it with VS Code and VS Code does make that suggestion.

Does anybody know why and how to fix it, so that WebStorm gives me correct suggestions in this case?

I was expecting to show .classList as an option as VS Code does but it is not doing it. I like WebStorm a lot more, but this has happened before in the past, making me think I am doing something wrong.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The issue occurs because the exact type of required[0].parentNode is not known (can't be retrieved statically) and the property classList does not exist on type ParentNode. You need letting the IDE know what the element actual type is (using JSdoc annotations, for example)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda