title: type annotation for parameter with default value
body: <p>In the following function definition:</p>
  
  <pre><code> function foo(a: number = 42): number {return a+1;}
  </code></pre>
  
  <p>&hellip; what are the semantics of the <code>a: number</code> annotation?</p>
  
  <p>Is it saying that variable <i>a</i> will always have a value inside
  the body of the function or is it saying that client programmers should always supply a value when they make the call?</p>
  
  <p>I've noticed that both the below code snippets type-check with no errors (with flow-bin 0.57.3):</p>
  
  <p><h2>snippet 1</h2></p>
  
  <pre><code>function foo(a: number = 42): number {return a+1;}
  type FooT= (a: number)=&gt; number
  
  (foo: FooT)
  
  foo();
  </code></pre>
  
  <p>(try it <a href="https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoKBXAdgYwC4CWcWYUccAFAIYBcYWGAtgEYCmATmALxgAsATAEo6DFhzABvdqzwZ2JKgGoAjAG4AvqjwBPAA6swAMXIAVHtRFM27QVwB89Kx1SoKZOHWNwTgl+4qCqkA" rel="noreferrer">here</a>)</p>
  
  <p><h2>snippet 2</h2></p>
  
  <pre><code>function foo(a: ?number = 42): number {return a+1;}
  type FooT = (a: ?number)=&gt; number
  
  (foo: FooT)
  
  foo();
  </code></pre>
  
  <p>(try it <a href="https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoKBXAdgYwC4CWcWYUccAFAIYBcYA-FhgLYBGApgE5gC8YALACYAlHSZsuYAN6d2eDJxJUA1AEYA3AF9UeAJ4AHdmABi5ACq8w1OoxYdOwngD4w4+6lQUycOqbhnhD28KYXUgA" rel="noreferrer">here</a>)</p>
  
  <p>What is the suggested way to annotate in such a case?</p>
  
  <p>My preference is with way #2 as the client programmer only has to look at the definition of the <code>FooT</code> type to realize that the parameter is optional. This allows me to tell users of my 
  library: "simply look at the type of the function (<code>FooT</code>)".</p>
  
  <p>Whereas with way #1 I have to tell them "the type of the function (<code>FooT</code>) seems to suggest that an argument is required, but in fact it isn't because, see, if you look at the implementation, a default value is supplied".</p>
  
  <p>So, which snippet is more idiomatic?</p>
  
  <p>Note that there is an <a href="https://stackoverflow.com/a/33097444/274677">answer</a> to a related question that seems to suggest that it is possible to annotate the type as mandatory in the implementation of a function and as optional in the declaration. But this doesn't seem to work in this case. E.g. the following doesn't type-check:</p>
  
  <pre><code>function foo(a: number = 42): number {return a+1;}
  type FooT = (a: ?number)=&gt; number
  
  (foo: FooT)
  
  foo();
  </code></pre>
  
  <p>(try it <a href="https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoKBXAdgYwC4CWcWYUccAFAIYBcYWGAtgEYCmATmALxgAsATAEo6DFhzABvdqzwZ2JKgGoAjAG4AvqjwBPAA6swAMXIAVbmGp0A-KLbtBXAHz0md1Kgpk4dY3BOD3LwpBVSA" rel="noreferrer">here</a>)</p>