title: Can an optional parameter be null in TypeScript?
body: <p>According to <a href="https://mariusschulz.com/blog/non-nullable-types-in-typescript" rel="noreferrer">this article</a>, when strict null checking is enabled in TypeScript, you cannot assign <code>null</code> or <code>undefined</code> to a variable unless it is explicitly allowed with a union.</p>
  
  <pre class="lang-js prettyprint-override"><code>// required value
  let req: string;
  req = "Something";  // OK
  req = null;      // Error
  req = undefined; // Error
  
  // nullable value
  let nbl: string | null;
  nbl = "Something";  // OK
  nbl = null;      // OK
  nbl = undefined; // Error
  </code></pre>
  
  <p>But is <code>null</code> allowed in an <em>optional</em> value in TypeScript?</p>
  
  <pre class="lang-js prettyprint-override"><code>// optional value
  let opt?: string; // (actually invalid, as optional types cannot be used for variable declarations, but that's not the point, so imagine we are dealing with function parameters or something)
  opt = "Something"; // OK
  opt = null; // OK? Error?
  opt = undefined; // OK
  </code></pre>
  
  <p>Or is</p>
  
  <pre class="lang-js prettyprint-override"><code>opt?: string;
  </code></pre>
  
  <p>equivalent to</p>
  
  <pre class="lang-js prettyprint-override"><code>opt: string | undefined;
  </code></pre>
  
  <p>thus not allowing <code>null</code> just like recommended by <a href="http://let%20name:%20string;%20name%20=%20%22Marius%22;%20%20//%20OK%20name%20=%20null;%20%20%20%20%20%20//%20Error%20name%20=%20undefined;%20//%20Error" rel="noreferrer">Microsoft's Coding guidelines</a>?</p>