title: Typecsript conditional type with unknown
body: <p>I was trying to correctly type following function:</p>
  
  <pre><code>function nullToUndefined(p: null): undefined;
  function nullToUndefined&lt;T extends Exclude&lt;unknown, null&gt;&gt;(p: T): T;
  function nullToUndefined&lt;T extends Exclude&lt;unknown, null&gt;&gt;(p: null | T): T | undefined
  {
      return p === null ? undefined : p; 
  }
  </code></pre>
  
  <p>It seems to be working fine for some cases:</p>
  
  <pre><code>const a = nullToUndefined(null); // undefined
  const b = nullToUndefined(true); // true 
  const c = nullToUndefined(10);   // 10
  </code></pre>
  
  <p>however it doesn't work for the following piece of code</p>
  
  <pre><code>const d = nullToUndefined(1 as number | null);
  </code></pre>
  
  <p>type of the variable d is <code>number | null</code> but i'd like to see <code>number | 
   undefined</code>. The problem seems to be in the <code>T extends Exclude&lt;unknown, null&gt;</code> - since unknown is a supertype of all types I would expect T to be everything except null, but obviously it doesn't work like this.</p>
  
  <p>For example I can do</p>
  
  <pre><code>const e: Exclude&lt;unknown, null&gt; = null;
  </code></pre>
  
  <p>and TS compiler doesn't complain.</p>
  
  <p>Is this behaviour expected or am I using unknown in an incorrect way? Is there any other way how to achieve correct typing for the function?</p>