title: How to avoid Flow typing error with empty array?
body: <p>I've encountered a Flow error that I deem to be a false negative.  Here's my pertinent code:</p>
  
  <pre><code>export type ValidationError = {
    name: string,
    id?: number,
    message: string
  }
  
  const determineErrorMessage = (name: string) =&gt; {
    if (!_.isEmpty(validationErrors)) {
      const error: ValidationError = validationErrors.find(error =&gt; error.name === name);
  
      if (error) {
        return (
          &lt;Form.Label className={classes.errorMessage}&gt;
            {error.message}
          &lt;/Form.Label&gt;      
        );
      } else {
        return null;
      }
    } else {
      return null;
    }
  }
  </code></pre>
  
  <p>The error is with this portion of the code:</p>
  
  <pre><code>validationErrors.find(error =&gt; error.name === name)
  </code></pre>
  
  <p>Flow is saying this:</p>
  
  <pre><code>Cannot assign `validationErrors.find(...)` to `error` because  undefined [1] is incompatible with  `ValidationError` 
  </code></pre>
  
  <p>I've done some reading about this and even consulted the related Flow documentation page: <a href="https://flow.org/en/docs/types/arrays/" rel="nofollow noreferrer">https://flow.org/en/docs/types/arrays/</a> About 2/3 of the way down this page, it says "As Flow is made to be smarter it may be possible in the future to fix this problem, but for now you should be aware of it."</p>
  
  <p>Should I just accept that I've done nothing wrong and that Flow will be improved in the future?</p>