Typescript Prevent Unbound / Uncalled Methods in Conditionals Without Strict NULL Checks

Viewed 42

For Angular / Typescript projects, I'm looking for a linting rule or similar means to prevent accidentally putting an unbound method in a conditional.

I'm looking for a linting rule / configuration that will work for projects using ES Lint, and with Typescript configured with strictNullChecks: false.

I would like for the following code to produce an error either at lint or compile time:

export class Example {

  constructor() {
    if (this.isStillThe1900s) {
      // the above should be an error because:
      console.error("this will always be true because we forgot () on this.isStillThe1900s()");
    }
  }

  private isStillThe1900s(): boolean {
    return (new Date()).getFullYear() < 2000;
  }
  
}

I know Typescript added this check back in 3.7, however according the documentation this check requires strict null checking to be enabled.

I've also tried

0 Answers
Related