title: How to fix the error "argument of type HTML element | null is not assignable to parameter of type 'TargetElement' using react testing library?
body: <p>i have a switch element in dom like so</p>
  <pre><code>&lt;div&gt;
      &lt;label for=&quot;source&quot;/&gt;
      &lt;label value=&quot;false&quot; class=&quot;StyledSwitch&quot;&gt;
          &lt;input type=&quot;checkbox&quot; name=&quot;source&quot; id=&quot;source&quot;&gt;
          &lt;i class=&quot;ball-container&quot;&gt;&lt;/i&gt;
          &lt;span class=&quot;label&quot; data-enabled=&quot;On&quot; data-disabled=&quot;Off&quot;&gt;&lt;/span&gt;
      &lt;/label&gt;
  &lt;/div&gt;
  </code></pre>
  <p>now i get the input element with id &quot;source&quot; using react-testing-library</p>
  <pre><code>const switch = document.getElementById('source')
  if (switch) {
      userEvent.click(switch);
  }
  </code></pre>
  <p>the above snippet works. but this switch is always present so i dont want to check for switch in if statement. when i remove if statement like below,</p>
  <pre><code>const switch = document.getElementById('source')
  userEvent.click(switch);
  </code></pre>
  <p>i get error like below,</p>
  <pre><code>&quot;argument of type HTML element | null is not assignable to parameter of type 'TargetElement' 
  </code></pre>
  <p>could someone help me fix this. thanks.</p>