title: Why TypeScript incorrectly infers the return type?
body: <p><strong>UPDATE:</strong> <strong>TypeScript message was correct</strong>, the return type of that function could be an empty string.</p>
  
  <p>The snippet below won't compile in TypeScript with <code>strictNullCheck</code> option.</p>
  
  <p>The code is correct, but TS wrongly infers that this <code>(id) =&gt; id &amp;&amp; /^[a-z0-9\-]+$/.test(id)</code> expression can return among other values empty string <code>''</code> and complains.</p>
  
  <pre><code>type Validators&lt;D&gt; = { 
    [K in keyof D]: (value: D[K] | undefined) =&gt; true | false | undefined
  }
  
  interface Post {
      id?: string
  }
  
  const validators: Validators&lt;Post&gt; = {
      // Complains about this line
      id: (id) =&gt; id &amp;&amp; /^[a-z0-9\-]+$/.test(id) 
  }
  </code></pre>
  
  <p><a href="https://www.typescriptlang.org/play/#src=type%20Validators%3CD%3E%20%3D%20%7B%20%0A%20%20%5BK%20in%20keyof%20D%5D%3A%20(value%3A%20D%5BK%5D%20%7C%20undefined)%20%3D%3E%20true%20%7C%20false%20%7C%20undefined%0A%7D%0A%0Ainterface%20Post%20%7B%0A%20%20%20%20id%3F%3A%20string%0A%7D%0A%0Aconst%20validators%3A%20Validators%3CPost%3E%20%3D%20%7B%0A%20%20%20%20id%3A%20(id)%20%3D%3E%20id%20%26%26%20%2F%5E%5Ba-z0-9%5C-%5D%2B%24%2F.test(id)%0A%7D" rel="nofollow noreferrer">Playground</a></p>