'Javascript inheritance and JSDoc - let base class know about type defined in derived class

Using JSDoc, is it possible to let a base class know about a param type defined in a derived class in javascript?

For example:

class ServiceBase {
  constructor(repository) {
    this.repository = repository;
  }
}

class MyRepository {
  someFunction() {}
}

class MyService extends ServiceBase {
  /**
   * @param {MyRepository} repository
   */
  constructor(repository) {
    super(repository);
  }

  doWork() {
    // JSDoc doesnt know about this this.repository.someFunction,
    // because it doesnt know the type of this.repostory
    this.repository.someFunction();
  }
}

The main thing I'm looking for is intellisense in VSCode, but since the repository instance type is not known by the MyService class, I cannot get prompts for functions etc.

I think I already know the answer is "no", but figure it's worth checking if anyone knows how to achieve this kind of thing.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source