title: In Typescript, what is type PoorMansUnknown = {} | null | undefined and how would you deal with it?
body: <p>Can someone please help me understand the meaning of the following type declaration...</p>
  
  <pre><code>type PoorMansUnknown = {} | null | undefined;
  </code></pre>
  
  <p>It is a TypeScript declaration and I have come across it in the context of the <a href="https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/history/index.d.ts#L54" rel="noreferrer">history</a> package.</p>
  
  <p>I have searched around to try and understand it myself but, given I'm quite new to TypeScript, it has me a bit stumped. I have found the following information on it:</p>
  
  <ul>
  <li><a href="https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/history/index.d.ts#L54" rel="noreferrer">original place I encountered it, history package</a></li>
  <li><a href="https://stackoverflow.com/questions/60586697/type-or-interface-for-location-state-in-react-router">a stackoverflow question that relates to the same history package</a></li>
  <li><a href="https://github.com/DefinitelyTyped/DefinitelyTyped/blob/8a31a2fe9e8417d47550db09e5f9f50fd09a8e60/types/node/globals.d.ts#L1160" rel="noreferrer">another package using the approach</a></li>
  <li><a href="https://twitter.com/OliverJAsh/status/1184505365012070400" rel="noreferrer">a twitter conversation on it</a> which hints that it relates to 'sort of' declaring a type for something you're not to sure about...</li>
  </ul>
  
  <p>My assumption is at this point, the author of this declaration intended it to be a way of saying... at runtime, this thing could be either an empty object or null or undefined.</p>
  
  <p>For more context, the way this type turned up on my radar is within the package <a href="https://www.npmjs.com/package/react-router-dom" rel="noreferrer">react-router-dom</a> (<a href="https://www.npmjs.com/package/@types/react-router-dom" rel="noreferrer">typedef here</a>). Specifically, I went to use the component <a href="https://reacttraining.com/react-router/web/api/Redirect" rel="noreferrer">Redirect</a> and it's property <a href="https://reacttraining.com/react-router/web/api/Redirect/to-object" rel="noreferrer">to: object</a> since I wanted to be able to tell the component I had routed to the location I was at previously</p>
  
  <p>e.g.        </p>
  
  <pre><code>&lt;Redirect to={{
    pathname: "/login",
    state: { from: "current-path }
   }} /&gt;
  </code></pre>
  
  <p>The doco for react router says...</p>
  
  <blockquote>
    <p>The state object can be accessed via this.props.location.state in the redirected-to component. This new referrer key (which is not a special name) would then be accessed via this.props.location.state.referrer in the Login component pointed to by the pathname '/login'</p>
  </blockquote>
  
  <p>So, I go to access props.location.state as such...</p>
  
  <pre><code>const { from }  = location.state || { from: { path: '/' } }
  </code></pre>
  
  <p>and I get an error</p>
  
  <pre><code>Property 'from' does not exist on type '{} | { from: { path: string; }; }'.
  </code></pre>
  
  <p>I trace this through the typedef chain, starting with <a href="https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6e9f8d6434fcc0561fef0bd20c70694fdb5a530d/types/history/index.d.ts#L29" rel="noreferrer">LocationState</a> and make my way down to the declaration for PoorMansUnknown</p>
  
  <p>This is where my confusion starts kicking in. What is this type? How should I deal with it?</p>
  
  <p>I found something related to it <a href="https://github.com/DefinitelyTyped/DefinitelyTyped/issues/41674#issuecomment-575588616" rel="noreferrer">here</a>, which says to cast it as <code>any</code>. So I did that, as such:</p>
  
  <pre><code>const { from }  = location.state as any || { from: { path: '/' } }
  </code></pre>
  
  <p>But I'm not sure about that. It does work, but is it just a workaround?</p>
  
  <hr>
  
  <p>Long story short, have you ever come across something like this before?</p>
  
  <pre><code>type PoorMansUnknown = {} | null | undefined;
  </code></pre>
  
  <p>and if so, what do you think it means and how would you work with components that make use of it?</p>