Search code examples
javascriptnode.jstypescriptwebstorm

TypeScript: Unsafe call of an `any` typed value when using a class defined in a js file


I have a class defined in ChargerPlan.js:

export default class ChargerPlan {
  constructor(...) {
    ...
  }

  /**
   * Creates a ChargerPlan object from a session.
   *
   * @param {ChargeSession} session - The charge session object.
   * @returns {ChargerPlan|null} - The created ChargerPlan object if all required properties are available,
   * null otherwise.
   */
  static createFromSession(session) {
    try {
      ...
      return new ChargerPlan(params);
    } catch {
      return null;
    }
  }
}

Then, when I try to use it in a TypeScript file:

import ChargerPlanClass from '#src/services/classes/ChargerPlan.js';

const plan = ChargerPlanClass.createFromSession(this);

I get an error saying "ESLint: Unsafe call of an any typed value.(@typescript-eslint/no-unsafe-call)" on ChargerPlanClass. WebStorm screenshot

I don't understand why ESLint complains that ChargerPlanClass is any. It is ChargerPlan class right? Do I miswrite JSDoc in js file, import statements in ts file, or something else like it's a WebStorm ESLint's bug? If I run eslint in command line, it finishes without errors.


Solution

  • You may need to restart ESLint (or the editor)
    ESLint sometimes forget to update dependency files when they are changed