A
A
Anton V.2021-05-13 12:08:22
JavaScript
Anton V., 2021-05-13 12:08:22

How to configure jsdoc to define dynamic return type when inheriting?

Good afternoon!
I really ask for help.

class ApiModel {
  item_class
  list = {}
  url

  loadItems() {
    fetch(this.url).then(data => {
      data.forEach(item => {
        // класс будет определен в наследумом классе
        let item_class = this.item_class
        this.list[item.id] = new item_class(item)
      })
    })
  }

  /**
   * @return Что тут писать ?
   */
  getList(){
    return this.list
  }

  /**
   * @param id
   * @return Что тут писать ?
   */
  getItem(id){
    return this.list[id]
  }
}


class ProductModel extends ApiModel {
  url='some-route'
  item_class = ProductItem
}

class ProductItem {
  constructor(data) {
    this.data = data
  }
  /**  методы сущнсоти **/
}


let product_model = new ProductModel()
let  product_item = product_model.getItem(id)


What needs to be written in the annotation so that the product_item is of the "ProductItem" type without declaring it explicitly in the ProductModel.

I can’t find how to implement it either ....
I would be very grateful !!!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question