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

264
Visualizações
How can I resolve a consistent-return error is eslint?

I've got this eslint error Expected to return a value at the end of arrow function consistent-return and even after reading the doc I still don't know how to handle it.

/**
 * @param selector
 * @returns {Promise<unknown>}
 */
let waitForElm = function(selector) {
    return new Promise(resolve => {
        if (document.querySelector(selector)) {
            return resolve(document.querySelector(selector));
        }

        const observer = new MutationObserver(() => {
            if (document.querySelector(selector)) {
                resolve(document.querySelector(selector));
                observer.disconnect();
            }
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    });
};

Any idea ?

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

0

You pass an arrow function to new Promise.

If document.querySelector(selector) is true, then you enter an if block and there is a return statement.

If it isn't true, then you go through the rest of the function and there isn't a return statement.

So sometimes there is a return and sometimes there isn't.

To be constant, there should always be a return.

So add one at the end of the function.

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