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

314
Views
TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead
interface A {
        a: () => boolean;
    }

    class AImpl implements A {
        public a(): boolean {
            return true;
        }
    }

    it('should fail', function () {
        const aImpl = new AImpl();
        if (aImpl.a) { // TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
            console.log("always true");
        }
    });

    it('why success', function () {
        const aImpl = new AImpl();
        if (!aImpl.a) { // nothing happens here
            console.log('always false');
        }
    });

why aImp.a reports TS2774, but !aImpl.a works well?

And is there any way to find the property-dereference on a method declaration?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As noted by Ramesh Reddy in the comments, if you call if(aImpl.a), it will always return true because you defined aImpl.a. You essentially convert the reference to this function to boolean that will always be true because the function is defined.

What you likely wanted to do is to call the function that you implemented.
In other words, if (aImpl.a()).

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!