<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function safeFindIndex&lt;T extends object&gt;(
  array: ReadonlyArray&lt;T&gt;,
  matcher: Partial&lt;T&gt;,
  recordName: string,
  assertMatcher: Partial&lt;T&gt; | undefined
): number {
  const index = findIndex(array, matcher)  // ERROR HERE: immutable-array.ts:21
  if (index === -1) {
    reportError(new TypeError(`Couldn't find ${recordName}`), { extra: { matcher } })
  } else {
    const found = array[index]
    if (assertMatcher !== undefined &amp;&amp; !isMatch(found, assertMatcher)) {
      reportError(
        new TypeError(`${recordName} was in unexpected state`),
        { extra: { record: found, assertMatcher } }
      )
    }
  }
  return index
}"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">safeFindIndex</span><span class="pl-c1">&lt;</span><span class="pl-smi">T</span> <span class="pl-k">extends</span> <span class="pl-smi">object</span><span class="pl-c1">&gt;</span><span class="pl-kos">(</span>
  <span class="pl-s1">array</span>: <span class="pl-smi">ReadonlyArray</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">,</span>
  <span class="pl-s1">matcher</span>: <span class="pl-smi">Partial</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">,</span>
  <span class="pl-s1">recordName</span>: <span class="pl-smi">string</span><span class="pl-kos">,</span>
  <span class="pl-s1">assertMatcher</span>: <span class="pl-smi">Partial</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span> <span class="pl-c1">|</span> <span class="pl-c1">undefined</span>
<span class="pl-kos">)</span>: <span class="pl-smi">number</span> <span class="pl-kos">{</span>
  <span class="pl-k">const</span> <span class="pl-s1">index</span> <span class="pl-c1">=</span> <span class="pl-en">findIndex</span><span class="pl-kos">(</span><span class="pl-s1">array</span><span class="pl-kos">,</span> <span class="pl-s1">matcher</span><span class="pl-kos">)</span>  <span class="pl-c">// ERROR HERE: immutable-array.ts:21</span>
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">index</span> <span class="pl-c1">===</span> <span class="pl-c1">-</span><span class="pl-c1">1</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">reportError</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-smi">TypeError</span><span class="pl-kos">(</span><span class="pl-s">`Couldn't find <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">recordName</span><span class="pl-kos">}</span></span>`</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-c1">extra</span>: <span class="pl-kos">{</span> matcher <span class="pl-kos">}</span> <span class="pl-kos">}</span><span class="pl-kos">)</span>
  <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-s1">found</span> <span class="pl-c1">=</span> <span class="pl-s1">array</span><span class="pl-kos">[</span><span class="pl-s1">index</span><span class="pl-kos">]</span>
    <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">assertMatcher</span> <span class="pl-c1">!==</span> <span class="pl-c1">undefined</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-c1">!</span><span class="pl-en">isMatch</span><span class="pl-kos">(</span><span class="pl-s1">found</span><span class="pl-kos">,</span> <span class="pl-s1">assertMatcher</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-en">reportError</span><span class="pl-kos">(</span>
        <span class="pl-k">new</span> <span class="pl-smi">TypeError</span><span class="pl-kos">(</span><span class="pl-s">`<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">recordName</span><span class="pl-kos">}</span></span> was in unexpected state`</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
        <span class="pl-kos">{</span> <span class="pl-c1">extra</span>: <span class="pl-kos">{</span> <span class="pl-c1">record</span>: <span class="pl-s1">found</span><span class="pl-kos">,</span> assertMatcher <span class="pl-kos">}</span> <span class="pl-kos">}</span>
      <span class="pl-kos">)</span>
    <span class="pl-kos">}</span>
  <span class="pl-kos">}</span>
  <span class="pl-k">return</span> <span class="pl-s1">index</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">This code causes this error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ERROR in [at-loader] TS2321: Excessive stack depth comparing types 'Partial&lt;T&gt;' and 'string | [string, any] | ListIterator&lt;T, boolean&gt; | PartialDeep&lt;T&gt; | undefined'.

ERROR in [at-loader] ./app/assets/javascripts/utilities/immutable-array.ts:21:34
    TS2321: Excessive stack depth comparing types 'Partial&lt;T&gt;' and 'string | [string, any] | ListIterator&lt;T, boolean&gt; | PartialDeep&lt;T&gt; | undefined'."><pre class="notranslate"><code class="notranslate">ERROR in [at-loader] TS2321: Excessive stack depth comparing types 'Partial&lt;T&gt;' and 'string | [string, any] | ListIterator&lt;T, boolean&gt; | PartialDeep&lt;T&gt; | undefined'.

ERROR in [at-loader] ./app/assets/javascripts/utilities/immutable-array.ts:21:34
    TS2321: Excessive stack depth comparing types 'Partial&lt;T&gt;' and 'string | [string, any] | ListIterator&lt;T, boolean&gt; | PartialDeep&lt;T&gt; | undefined'.
</code></pre></div>
<p dir="auto"><strong>package versions</strong></p>
<ul dir="auto">
<li><code class="notranslate">@types/lodash@4.14.108</code></li>
<li><code class="notranslate">typescript@2.8.1</code></li>
</ul>
<p dir="auto">This is not an issue with <code class="notranslate">@types/lodash@4.14.106</code></p>
<p dir="auto"><strong>cc:</strong> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/aj-r/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/aj-r">@aj-r</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/andy-ms/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/andy-ms">@andy-ms</a></p>
<p dir="auto"><strong>Search Terms:</strong><br>
"excessive depth"<br>
"generic partial"</p>
<p dir="auto"><strong>Code</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const fn = &lt;T&gt;(arg: T) =&gt; {
    ((arg2: RecursivePartial&lt;T&gt;) =&gt; {
        // ...
    })(arg); // &lt;-- here
};

type RecursivePartial&lt;T&gt; = {
    [P in keyof T]?: RecursivePartial&lt;T[P]&gt;;
};"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-en">fn</span> <span class="pl-c1">=</span> <span class="pl-c1">&lt;</span><span class="pl-smi">T</span><span class="pl-c1">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">arg</span>: <span class="pl-smi">T</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-s1">arg2</span>: <span class="pl-smi">RecursivePartial</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-c">// ...</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-s1">arg</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// &lt;-- here</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-k">type</span> <span class="pl-smi">RecursivePartial</span><span class="pl-c1">&lt;</span><span class="pl-smi">T</span><span class="pl-c1">&gt;</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
    <span class="pl-kos">[</span><span class="pl-smi">P</span> <span class="pl-k">in</span> <span class="pl-k">keyof</span> <span class="pl-smi">T</span><span class="pl-kos">]</span>?: <span class="pl-smi">RecursivePartial</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">[</span><span class="pl-smi">P</span><span class="pl-kos">]</span><span class="pl-kos">&gt;</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong><br>
Comparing a generic with a partial of that generic working without errors.</p>
<p dir="auto"><strong>Actual behavior:</strong><br>
Getting "Excessive stack depth comparing types 'T' and 'RecursivePartial'." since upgrading to 2.7.x. (Also errors in 2.8.x). Working in 2.6.1.</p>
<p dir="auto"><strong>Playground Link:</strong><br>
<a href="https://www.typescriptlang.org/play/index.html#src=class%20Greeter%20%7B%0D%0A%20%20%20%20greeting%3A%20RecursivePartial%3Cstring%3E%3B%0D%0A%20%20%20%20constructor(message%3A%20string)%20%7B%0D%0A%20%20%20%20%20%20%20%20this.greeting%20%3D%20message%3B%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20greet()%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20%22Hello%2C%20%22%20%2B%20this.greeting%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Alet%20greeter%20%3D%20new%20Greeter(%22world%22)%3B%0D%0A%0D%0Alet%20button%20%3D%20document.createElement('button')%3B%0D%0Abutton.textContent%20%3D%20%22Say%20Hello%22%3B%0D%0Abutton.onclick%20%3D%20function()%20%7B%0D%0A%20%20%20%20alert(greeter.greet())%3B%0D%0A%7D%0D%0A%0D%0Adocument.body.appendChild(button)%3B%0D%0A%0D%0Aconst%20fn%20%3D%20%3CT%3E(arg%3A%20T)%20%3D%3E%20%7B%0D%0A%20%20%20%20((arg2%3A%20RecursivePartial%3CT%3E)%20%3D%3E%20%7B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%0D%0A%20%20%20%20%7D)(arg)%3B%0D%0A%7D%3B%0D%0A%0D%0Atype%20RecursivePartial%3CT%3E%20%3D%20%7B%0D%0A%20%20%20%20%5BP%20in%20keyof%20T%5D%3F%3A%20RecursivePartial%3CT%5BP%5D%3E%3B%0D%0A%7D%3B" rel="nofollow">https://www.typescriptlang.org/play/index.html#src=class%20Greeter%20%7B%0D%0A%20%20%20%20greeting%3A%20RecursivePartial%3Cstring%3E%3B%0D%0A%20%20%20%20constructor(message%3A%20string)%20%7B%0D%0A%20%20%20%20%20%20%20%20this.greeting%20%3D%20message%3B%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20greet()%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20%22Hello%2C%20%22%20%2B%20this.greeting%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Alet%20greeter%20%3D%20new%20Greeter(%22world%22)%3B%0D%0A%0D%0Alet%20button%20%3D%20document.createElement('button')%3B%0D%0Abutton.textContent%20%3D%20%22Say%20Hello%22%3B%0D%0Abutton.onclick%20%3D%20function()%20%7B%0D%0A%20%20%20%20alert(greeter.greet())%3B%0D%0A%7D%0D%0A%0D%0Adocument.body.appendChild(button)%3B%0D%0A%0D%0Aconst%20fn%20%3D%20%3CT%3E(arg%3A%20T)%20%3D%3E%20%7B%0D%0A%20%20%20%20((arg2%3A%20RecursivePartial%3CT%3E)%20%3D%3E%20%7B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%0D%0A%20%20%20%20%7D)(arg)%3B%0D%0A%7D%3B%0D%0A%0D%0Atype%20RecursivePartial%3CT%3E%20%3D%20%7B%0D%0A%20%20%20%20%5BP%20in%20keyof%20T%5D%3F%3A%20RecursivePartial%3CT%5BP%5D%3E%3B%0D%0A%7D%3B</a></p>
<p dir="auto"><strong>Related Issues:</strong><br>
None?</p>