title: How to check if an object is an instance of a Flow type?
body: <p>I have two Flow types set up:</p>
  
  <pre><code>type Form1Fields = {
      fieldA
  }
  
  type Form2Fields = {
      fieldZ
  }
  
  type FormFields = Form1Fields | Form2Fields
  </code></pre>
  
  <p>Then I function that accepts a <code>FormFields</code> object as a parameter:</p>
  
  <pre><code>const myFunction = (fields: FormFields) =&gt; return fields.fieldA;
  </code></pre>
  
  <p>That's giving me the error <code>Cannot get fields.fieldA because property fieldA is missing on Form2Fields</code>.</p>
  
  <p>I get what it's saying. According to the <a href="https://flow.org/en/docs/types/unions/" rel="nofollow noreferrer">Flow docs</a>, "when calling our function that accepts a union type we must pass in one of those types. But inside of our function we are required to handle <strong>all of the possible types</strong>."</p>
  
  <p>So in <code>myFunction</code>, I'd need to do something like:</p>
  
  <pre><code>if (typeof fields === Form1Fields) { ... }
  else { ... }
  </code></pre>
  
  <p>I could do that with primitive types like <code>number</code>, but it doesn't seem like I can do that with Flow types.</p>
  
  <p>Is there a way to compare an object to Flow types, or is there a different way of solving this problem?</p>