<blockquote>
<p dir="auto">Issue originally reported by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/babel-bot/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/babel-bot">@babel-bot</a> in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="201397492" data-permission-text="Title is private" data-url="https://github.com/babel/babylon/issues/306" data-hovercard-type="issue" data-hovercard-url="/babel/babylon/issues/306/hovercard" href="https://github.com/babel/babylon/issues/306">babel/babylon#306</a></p>
</blockquote>
<p dir="auto">Original issue submitted by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gsathya/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gsathya">@gsathya</a> in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="201167564" data-permission-text="Title is private" data-url="https://github.com/babel/babel/issues/5145" data-hovercard-type="issue" data-hovercard-url="/babel/babel/issues/5145/hovercard" href="https://github.com/babel/babel/issues/5145">#5145</a></p>


<h3 dir="auto">Input Code</h3>


<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="result = { __proto__: x, __proto__: y } = value;"><pre class="notranslate"><span class="pl-s1">result</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span> <span class="pl-c1">__proto__</span>: <span class="pl-s1">x</span><span class="pl-kos">,</span> <span class="pl-c1">__proto__</span>: <span class="pl-s1">y</span> <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-s1">value</span><span class="pl-kos">;</span></pre></div>
<h3 dir="auto">Babel Configuration (.babelrc, package.json, cli command)</h3>

<p dir="auto">presets - latest</p>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">No error</p>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">Error: <code class="notranslate">Redefinition of __proto__ property</code></p>


<h3 dir="auto">Possible Solution</h3>


<h3 dir="auto">Context</h3>


<h3 dir="auto">Your Environment</h3>

<table role="table">
<thead>
<tr>
<th>software</th>
<th>version</th>
</tr>
</thead>
<tbody>
<tr>
<td>Babel</td>
<td></td>
</tr>
<tr>
<td>node</td>
<td></td>
</tr>
<tr>
<td>npm</td>
<td></td>
</tr>
<tr>
<td>Operating System</td>
<td></td>
</tr>
</tbody>
</table>
<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>Current Behavior</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TypeError: Property types[0] of UnionTypeAnnotation expected node to be of a type [&quot;FlowType&quot;] but instead got &quot;TSTypeAnnotation&quot;
    at validate (/work/node_modules/@babel/types/lib/definitions/utils.js:128:13)
    at validator (/work/node_modules/@babel/types/lib/definitions/utils.js:97:7)
    at Object.validate (/work/node_modules/@babel/types/lib/definitions/utils.js:172:7)
    at validate (/work/node_modules/@babel/types/lib/validators/validate.js:17:9)
    at builder (/work/node_modules/@babel/types/lib/builders/builder.js:46:27)
    at UnionTypeAnnotation (/work/node_modules/@babel/types/lib/builders/generated/index.js:733:31)
    at Object.createUnionTypeAnnotation (/work/node_modules/@babel/types/lib/builders/flow/createUnionTypeAnnotation.js:20:47)
    at NodePath.ConditionalExpression (/work/node_modules/@babel/traverse/lib/path/inference/inferers.js:124:14)
    at NodePath._getTypeAnnotation (/work/node_modules/@babel/traverse/lib/path/inference/index.js:63:20)
    at NodePath.getTypeAnnotation (/work/node_modules/@babel/traverse/lib/path/inference/index.js:29:19)"><pre class="notranslate"><code class="notranslate">TypeError: Property types[0] of UnionTypeAnnotation expected node to be of a type ["FlowType"] but instead got "TSTypeAnnotation"
    at validate (/work/node_modules/@babel/types/lib/definitions/utils.js:128:13)
    at validator (/work/node_modules/@babel/types/lib/definitions/utils.js:97:7)
    at Object.validate (/work/node_modules/@babel/types/lib/definitions/utils.js:172:7)
    at validate (/work/node_modules/@babel/types/lib/validators/validate.js:17:9)
    at builder (/work/node_modules/@babel/types/lib/builders/builder.js:46:27)
    at UnionTypeAnnotation (/work/node_modules/@babel/types/lib/builders/generated/index.js:733:31)
    at Object.createUnionTypeAnnotation (/work/node_modules/@babel/types/lib/builders/flow/createUnionTypeAnnotation.js:20:47)
    at NodePath.ConditionalExpression (/work/node_modules/@babel/traverse/lib/path/inference/inferers.js:124:14)
    at NodePath._getTypeAnnotation (/work/node_modules/@babel/traverse/lib/path/inference/index.js:63:20)
    at NodePath.getTypeAnnotation (/work/node_modules/@babel/traverse/lib/path/inference/index.js:29:19)
</code></pre></div>
<p dir="auto"><strong>Input Code</strong></p>
<p dir="auto"><a href="https://github.com/azz/babel-typescript-union-bug">https://github.com/azz/babel-typescript-union-bug</a></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function bug() {
  const x = 1 ? a() : b();

  return [...x];
}

function a(): number[] {
  return [];
}

function b(): number[] {
  return [];
}"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">bug</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">const</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span> ? <span class="pl-en">a</span><span class="pl-kos">(</span><span class="pl-kos">)</span> : <span class="pl-en">b</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-kos">[</span>...<span class="pl-s1">x</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">a</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">number</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-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">b</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">number</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-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Expected behavior/code</strong></p>
<p dir="auto"><em>Not like this</em></p>
<p dir="auto"><strong>Babel Configuration (.babelrc, package.json, cli command)</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;plugins&quot;: [&quot;@babel/plugin-transform-spread&quot;],
  &quot;presets&quot;: [&quot;@babel/preset-typescript&quot;]
}"><pre class="notranslate"><span class="pl-kos">{</span>
  <span class="pl-s">"plugins"</span>: <span class="pl-kos">[</span><span class="pl-s">"@babel/plugin-transform-spread"</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
  <span class="pl-s">"presets"</span>: <span class="pl-kos">[</span><span class="pl-s">"@babel/preset-typescript"</span><span class="pl-kos">]</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Environment</strong></p>
<ul dir="auto">
<li>Babel version(s): 7.3.3</li>
<li>Node/npm version: 6.5.0</li>
<li>OS: macOS 10.14.2</li>
<li>Monorepo: no</li>
<li>How you are using Babel: cli</li>
</ul>
<p dir="auto"><strong>Possible Solution</strong></p>
<p dir="auto">The builder code for <code class="notranslate">plugin-transform-spread</code> is expecting a <code class="notranslate">UnionTypeAnnotation</code> instead of a <code class="notranslate">TSUnionType</code> in order to determine the type of <code class="notranslate">x</code> above, specifically in <code class="notranslate">scope.toArray</code>:</p>
<p dir="auto"></p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/babel/babel/blob/5bb1bb080f2cb1ff942c940bdb9595a70e6f4706/packages/babel-traverse/src/scope/index.js#L408-L413">babel/packages/babel-traverse/src/scope/index.js</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 408 to 413
      in
      <a data-pjax="true" class="commit-tease-sha" href="/babel/babel/commit/5bb1bb080f2cb1ff942c940bdb9595a70e6f4706">5bb1bb0</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L408" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="408"></td>
          <td id="LC408" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">isIdentifier</span><span class="pl-kos">(</span><span class="pl-s1">node</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L409" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="409"></td>
          <td id="LC409" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">const</span> <span class="pl-s1">binding</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-en">getBinding</span><span class="pl-kos">(</span><span class="pl-s1">node</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L410" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="410"></td>
          <td id="LC410" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">binding</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">binding</span><span class="pl-kos">.</span><span class="pl-c1">constant</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">binding</span><span class="pl-kos">.</span><span class="pl-c1">path</span><span class="pl-kos">.</span><span class="pl-en">isGenericType</span><span class="pl-kos">(</span><span class="pl-s">"Array"</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L411" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="411"></td>
          <td id="LC411" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-k">return</span> <span class="pl-s1">node</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L412" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="412"></td>
          <td id="LC412" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-kos">}</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L413" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="413"></td>
          <td id="LC413" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-kos">}</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto"><code class="notranslate">isGenericType</code> ends up calling <code class="notranslate">createUnionTypeAnnotation</code>:</p>
<p dir="auto"></p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/babel/babel/blob/5bb1bb080f2cb1ff942c940bdb9595a70e6f4706/packages/babel-traverse/src/path/inference/inferers.js#L92-L97">babel/packages/babel-traverse/src/path/inference/inferers.js</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 92 to 97
      in
      <a data-pjax="true" class="commit-tease-sha" href="/babel/babel/commit/5bb1bb080f2cb1ff942c940bdb9595a70e6f4706">5bb1bb0</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L92" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="92"></td>
          <td id="LC92" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">export</span> <span class="pl-k">function</span> <span class="pl-v">ConditionalExpression</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L93" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="93"></td>
          <td id="LC93" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">return</span> <span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">createUnionTypeAnnotation</span><span class="pl-kos">(</span><span class="pl-kos">[</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L94" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="94"></td>
          <td id="LC94" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s">"consequent"</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">getTypeAnnotation</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L95" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="95"></td>
          <td id="LC95" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s">"alternate"</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">getTypeAnnotation</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L96" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="96"></td>
          <td id="LC96" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L97" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="97"></td>
          <td id="LC97" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-kos">}</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">Which creates a <code class="notranslate">UnionTypeAnnotation</code>, which works for Flow, but not TypeScript.</p>