title: Making a type guard for an interface with all optional properties
body: <p>I have a function <code>makeMergedState</code> which takes either an object or an array of type <code>ICustomState</code>.</p>
  
  <p>The functions contains conditional statements depending on whether the input is a valid ICustomState or ICustomState[]. In case of the input being an invalid object erroneously type casted, I want the function to throw.</p>
  
  <p>This is the test case I want to succeed:</p>
  
  <pre><code>it("throws on invalid input", () =&gt; {
    expect(() =&gt; makeMergedState({ test: "" } as ICustomState)).toThrow();
  });
  </code></pre>
  
  <p>ICustomState is a TypeScript interface containing only optional properties. I can type guard the array with such a function:
  <code>const isCustomStateArray = (p: any): p is ICustomState[] =&gt; !!p[0];</code></p>
  
  <p>However, I can't find a way to make an equivalent <code>isCustomState</code> type guard, and I think this is a limitation of how type guards work with the type system.</p>
  
  <p>According to <a href="https://github.com/microsoft/TypeScript/issues/5842" rel="nofollow noreferrer">this</a> GitHub issue, it's possible to work around this limitation with <a href="https://github.com/microsoft/TypeScript/issues/4895" rel="nofollow noreferrer">tag types</a>, but I'm unsure how.</p>
  
  <p>Greatly appreciate any suggestion. </p>
  
  <p>EDIT: <a href="https://codesandbox.io/s/sleepy-fire-54vwc?fontsize=14&amp;hidenavigation=1&amp;previewwindow=tests&amp;theme=dark" rel="nofollow noreferrer">Codesandbox example</a></p>