title: What is a correct type for a nullable function variable in typescript?
body: <p>I have this bit of code</p>
  
  <pre><code>let anchorRenderer: string =&gt; React.Component;  // line 658
  if (link) {
      if (userAnchorRenderer) {
        anchorRenderer = userAnchorRenderer;  // line 661
      } else {
        anchorRenderer = (link: string) =&gt; &lt;a className={styles.link} href={link}/&gt;    // line 663
      }
  }
  
  ...
  
  // Usage of the function 
  return &lt;div&gt;
      {anchorRenderer &amp;&amp; anchorRenderer(link)})   
   &lt;/div&gt;
  </code></pre>
  
  <p>But I am not able to get the type declaration right.</p>
  
  <p>In this version, I got these errors:</p>
  
  <pre><code>Error:(663, 11) TS2322: Type 'P["anchorRenderer"]' is not assignable to type 'string'.
    Type '((link: string) =&gt; Component&lt;{}, {}, any&gt;) | undefined' is not assignable to type 'string'.
      Type 'undefined' is not assignable to type 'string'.
  Error:(663, 11) TS2322: Type '(link: string) =&gt; Element' is not assignable to type 'string'.
  </code></pre>
  
  <p>If I changed the variable declaration to </p>
  
  <pre><code>let anchorRenderer: string =&gt; React.Component | undefined;
  </code></pre>
  
  <p>I got this error instead</p>
  
  <pre><code>Error:(658, 35) TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
  </code></pre>
  
  <p>How can I fix the type declaration?</p>