title: flow types with constant strings, and dependent types
body: <p>Say I have the following constant string:</p>
  
  <p><code>export default const FOO = 'FOO'</code></p>
  
  <p>Say I import this in a flow annotated file like so:</p>
  
  <p><code>import FOO from '../consts/Foo'</code></p>
  
  <p>I then have a function:</p>
  
  <pre><code>const example = (foo : string) : {| type: FOO, foo: string |} =&gt; {
    return {type: FOO, foo: foo}
  }
  </code></pre>
  
  <p>This doesn't typecheck with:</p>
  
  <pre class="lang-none prettyprint-override"><code>  6: const example = (foo : string) : {| type: FOO, foo: string |}=&gt; {
                                                           ^^^^^^^^^^^^^^ string. Ineligible value used in/as type annotation (did you forget 'typeof'?)
    6: const example = (foo : string) : {| type: FOO, foo: string |}=&gt; {
                                                           ^^^^^^^^^^^^^^ FOO
  </code></pre>
  
  <p>So my questions are: </p>
  
  <p>1) is it possible to use constants in flow types, how can I reproduce this behaviour? </p>
  
  <p>2) Is it possible to do dependent types in flow? so for example, could I encode, through types, that the string that is returned must be the same string that is passed into the <code>example</code> function?</p>
  
  <p>EDIT: Clarification to part 2: Is it possible to in some way indicate that the <code>foo</code> parameter passed into the <code>example</code> function is in fact the same string as the string at the <code>foo</code> key in the return object? Or to assert that the input and output have the same length (for say a shift cipher function). Or say contain a permutation of the same characters? (for a shuffle).</p>
  
  <p><a href="https://en.wikipedia.org/wiki/Dependent_type" rel="noreferrer">https://en.wikipedia.org/wiki/Dependent_type</a></p>