title: How to set types for mounting function in enzyme tests?
body: <p>I'm using Typescript and Enzyme for testing react components. I'm very new to Typescript.</p>
  
  <p>I've got this helper function in tests:</p>
  
  <pre><code>const getComponent = (mountFn = shallow) =&gt; (
    mountFn(&lt;Component /&gt;)
  )
  </code></pre>
  
  <p>This works when I run it as <code>getComponent()</code> but as soon I do <code>getComponent(mount)</code> it fails because typescript assumes <code>getComponent</code> returns ShallowWrapper.</p>
  
  <p>I have a couple of questions:</p>
  
  <ol>
  <li>How do I tell Typescript that <code>mountFn</code> can be either <code>shallow</code> or <code>mount</code>?</li>
  <li>How do I tell it that the return value can be of type <code>ShallowWrapper</code> or <code>ReactWrapper</code>?</li>
  <li>Ideally - how do I tell it that the return value should be of type <code>ShallowWrapper</code> when <code>shallow</code> was passed and <code>ReactWrapper</code> when <code>mount</code> was passed?</li>
  <li>How do I do this using typings that are already defined in @types/enzyme?</li>
  <li>Is this a good practice at all? I used to do it all the time before using typescript but maybe I should just create 2 separate functions?</li>
  </ol>