title: Typescript class with generic type that cannot be itself
body: <p>Is it possible to prevent nested use of a class with a generic type parameter, i.e., <code>Optional&lt;Optional&lt;string&gt;&gt;</code>? Example class:</p>
  <pre class="lang-js prettyprint-override"><code>export default abstract class Optional&lt;T&gt; {
    abstract get hasValue(): boolean
    abstract get value(): T
  
    static of&lt;U&gt;(value: U): Optional&lt;U&gt; { return new FilledOptional&lt;U&gt;(value) }
    static empty&lt;U&gt;(): Optional&lt;U&gt; { return new EmptyOptional&lt;U&gt;() }
  }
  </code></pre>
  <p>This abstract class has no constructor to limit instance creation. The exact implementation of <code>FilledOptional</code> and <code>EmptyOptional</code> classes that <code>of</code> and <code>empty</code> use don't seem relevant.</p>
  <p>And this is invalid: <code>class Optional&lt;T extends Optional&lt;unknown&gt; ? never : T&gt;</code>.</p>
  <p>Is there some way to practically do this at the global class level, or do I just have to decorate every possible method parameter in this class and related classes with a similar type constraint?</p>
  <p>Just now I realized the possibility of some <code>instanceof</code> checking in the <code>of</code> method, but that won't help with the <code>empty</code> method.</p>
  <p>Or, is it best to simply let this class be used in any possible way, even though (in my mind), a directly nested <code>Optional</code> is for now an anti-pattern I'd like to avoid in the codebase.</p>