title: How can I cast or change the generic type in TypeScript?
body: <pre><code>function cast&lt;R, T&gt;(v: T): R {
    return v as R;
           ~~~~~~
           // Error
  }
  </code></pre>
  
  <p>So what I'm trying to do is to change the type of <code>v</code> from T to R. But, I see the error following.</p>
  
  <pre><code>Conversion of type 'T' to type 'R' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
    'T' is assignable to the constraint of type 'R', but 'R' could be instantiated with a different subtype of constraint '{}'.
  </code></pre>
  
  <p>And using <code>InstanceType&lt;typeof R&gt;</code> also gives me an error.
  Is there somebody who knows how to do this?</p>