title: JSDoc: how to document a function that returns an instance of a passed constructor?
body: <p>For instance, I have the following function:</p>
  
  <pre><code>function createInstanceOf(ObjectConstructor) {
    return new ObjectConstructor;
  }
  </code></pre>
  
  <p>I want to make WebStorm autocompletion working when I pass a class as an argument. For example: if I call <code>createInstanceOf(ClassA)</code> I want to see autocompletion for <code>ClassA</code> instance, if I call <code>createInstanceOf(ClassB)</code> – for <code>ClassB</code> instance. So JSDoc function has to be generic.</p>
  
  <p>It's easy to define a generic function with JSDoc and make <code>@return</code> value type be the same as <code>@param</code>, but I've found no way to treat <code>@param</code> type as a constructor for returned object.</p>
  
  <p>So this doesn't work:</p>
  
  <pre><code>/**
   * @param {T} ObjectConstructor
   * @returns {T}
   * @template T
   */
  function createInstanceOf(ObjectConstructor) {
    return new ObjectConstructor;
  }
  </code></pre>
  
  <p>I also tried to make it working this way:</p>
  
  <pre><code>/**
   * @param {function(new:T)} ObjectConstructor
   * @returns {T}
   * @template T
   */
  function createInstanceOf(ObjectConstructor) {
    return new ObjectConstructor;
  }
  </code></pre>
  
  <p>But maybe I use closure types wrong, or WebStorm can't resolve such generic types.</p>
  
  <p>If there're several solutions for JSDoc, I'd like to find out which ones work specifically with WebStorm IDE autocompletion.</p>
  
  <p>Thank you</p>