title: How to declare that a var has now been initialized, if Flow can't infer it automatically?
body: <p>Try <a href="https://flowtype.org/try/#0MYewdgzgLgBGCuBbARgUwE4RgXhgbQEYAaGAJhIGYSAWEgVgF0BuAKBYBtVZEBDADwBccJGnSsWCFBggA6AGYh0AUR7AAFgAoAllFSIcAPhgBvFjBha5MDQEJefGAB9HF3fqP2AlDHs5Xe1gBfT3FQSBBOGXYQAHMNewBqBJCYAHpUmCgATwAHVBgMdEUWIA" rel="nofollow noreferrer">this code in Flow's REPL</a>:</p>
  
  <pre><code>const numbers = [5, 3, 22, 2, 6];
  
  let max: number;
  
  numbers.forEach(item =&gt; {
    if (!max || item &gt; max) max = item;
  });
  
  console.log(max++); // type error
  </code></pre>
  
  <p>I can be certain that <code>max</code> will have been initialized as a number before the <code>max++</code> expression. But Flow can't infer this automatically, so it complains.</p>
  
  <p>I want to say to Flow, after the forEach: please assume the <code>max</code> variable has now been initialized. Is there a way to do this?</p>
  
  <p>(Related – Flow has 'declarations': <code>declare var max: number;</code> – this lets you declare that a number variable called <code>var</code> exists in global scope. But you can't use it to redeclare something already declared in your own scope.)</p>