title: React TypeScript: Correct type for useLocation() from react-router-dom
body: <p>I'm struggling to find the right type for this situation. This is a simplified version of redirecting after login. The following produces a compiler error:</p>
  
  <pre><code>Property 'from' does not exist on type '{} | { from: { pathname: string; }; }'.
  </code></pre>
  
  <p>Adding <code>as any</code> to the use of <code>location.state</code> fixes the compiler error but it's ugly and the linter complains. </p>
  
  <pre><code>import React from "react";
  import { useLocation } from "react-router-dom";
  
  const AuthLayer: React.FC = (props) =&gt; {
    const location = useLocation();
  
    const { from } = location.state || { from: { pathname: "/" } };
  
    return &lt;p&gt;&lt;/p&gt;;
  };
  
  export default AuthLayer;
  </code></pre>