title: Write JSdoc for generic function in typescript
body: <p>I've distilled an essence of my problem with following codes:</p>
  
  <p><a href="https://jsfiddle.net/3Lhtrkqj/" rel="nofollow noreferrer">full source</a></p>
  
  <p>I have Base class, and Derived, Derived2: </p>
  
  <pre><code>class Base {
      static get type() {
          return 'Base';
      }
  }
  
  class Derived extends Base {
  }
  
  class Derived2 extends Base {
  }
  </code></pre>
  
  <p>Now I have variable t, which could be an instance of Derived or Derived2. It can also be changed multiple times during runtime.</p>
  
  <pre><code>/** @type {Base} */
  var t = new Derived();
  //or
  var t = new Derived2();
  </code></pre>
  
  <p>And I have a function which checks whether t is an instance of passed-class, and returns t if it's an instance of the passed class or undefined otherwise.</p>
  
  <pre><code>/**
   * @template {typeof Base} T
   * @param {T} cl
   * @returns {T}  /// &lt;-- I can't figure out how to return an instance of T
   * @returns {instanceof T} /// it's hypothetical, but I need this..
   */
  function checkTop( cl ) {
      if ( t instanceof cl ) {
          return t;
      }
      return undefined;
  }
  </code></pre>
  
  <p>When I call checkTop( Derived ), its return type should be Derived. But with above jsdoc, its return type is 'typeof Derived'.
  But I want to make the return type just 'Derived'.</p>
  
  <pre><code>let d1 = checkTop( Derived ); // 'typeof Derived', but I want 'Derived' as return type
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/kbiTE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kbiTE.png" alt="d1 is recognized as &#39;typeof Derived&#39;"></a></p>
  
  <p>likewise, d2 is recognized as 'typeof Derived2'</p>
  
  <pre><code>let d2 = checkTop( Derived2 ); // 'typeof Derived2'.. but I want 'Derived2' as return type
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/syoNl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/syoNl.png" alt="d2 is recognized as &#39;typeof Derived2&#39;"></a></p>
  
  <p>How can I specify the return type in JSDOC so that <code>checkTop( Derived );</code> has return type as <code>Derived</code>, and <code>checkTop( Derived2 )</code>'s return type is 'Derived2'.</p>
  
  <p>I tried following for the return type:</p>
  
  <pre><code>/**
   * @template {Base} B 
   * @template {typeof B} T
   * @param {T} cl
   * @returns {B}
   */
  function checkTop( cl )
  </code></pre>
  
  <p>and</p>
  
  <pre><code>/**
   * @template {typeof Base} T
   * @param {T} cl
   * @returns {instanceof T}
   */
  function checkTop( cl )
  </code></pre>
  
  <p>If it's not possible in JSDOC, but possible in typescript, that would be helpful also, but I prefer JSDOC solution.</p>