Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!