title: Why doesn't TypeScript complain about an incorrect return type?
body: <p>Please consider this example:</p>
  <pre class="lang-js prettyprint-override"><code>// all properties in Item should be optional, this is by design
  type Item = {
      id?: number
      name?: string
  }
  
  interface WithVersion {
      version: number
  }
  
  export type ResultType =
      &amp; WithVersion // #1 try to remove it
      &amp; {
          version: number
          list: Item[];
      };
  
  
  export interface Data {
      list: Array&lt;string&gt;;
  }
  
  // As per my understanding, this function should not compile, because elem.list is not assignable to list in ResultType
  const builder = &lt;T extends Data&gt;(data: Array&lt;T&gt;): ResultType[] =&gt; {
      const result = data.map((elem) =&gt; ({
          list: elem.list, // #2 list is string[], whereas ResultType expects list to be Item[]
          version: 2,
      }))
      return result // #3
  }
  </code></pre>
  <p><a href="https://www.typescriptlang.org/play?#code/C4TwDgpgBAksEFsoF4oG8BQVtQJYBMB+ALigDsBXBAIwgCcscyBDBCEqAZ2DtzIHMMAXwwY+8OgDNmAY2gB1XMAAWANXqdcAezLpG2AG4btZUpRr1hoiAA8wWusCihIUAEoROFADbAAKuDQyPpQAGRQiirqdJo6UAD08VAAxACMznQgzlpQdIhaRnjAIeGYOOVQRjEmZlS0DBU43rjcpHCIANoAugDcIUJ91nYOTuL00nJQACLMwMx65c2tUACCdHTMIAA83LwCAHx9IhgyOtxQ1BS43vj0KFBbflC28GT4nNOzzPsAFPhfpDWG22fn2AEpSB4vL4ApBuih9gscKcyOc8tCnKh-nMAHQIZhgH4-CDeRBghFQH5lRpQJbAUgkxA4ukAGgSSWSACZaS1Rh9dnx+N02QB3ZT0CDMD5Qnz+QLPOwQGTAD507IXaDtBDdELlKqxUxQTks-pgsEhPLACh0XTo2XslIAZmEQA" rel="noreferrer">Playground link</a></p>
  <p>I am a bit confused by the assignability rules of TypeScript.</p>
  <p>Try to remove <code>WithVersion</code> from <code>ResultType</code>. TypeScript will complain about the assignability of <code>result</code> to return type of <code>builder</code> function (<code>ResultType</code>).</p>
  <p>Further more, if you define explicit return type for <code>Array.prototype.map</code> callback, TypeScript will complain just as I expect:</p>
  <pre class="lang-js prettyprint-override"><code>const builder = &lt;T extends Data&gt;(data: Array&lt;T&gt;): ResultType[] =&gt; {
      const result = data.map((elem):ResultType =&gt; ({
          list: elem.list, // error as expected
          version: 2,
      }))
      return result
  }
  </code></pre>
  <p>My questions are:</p>
  <ol>
  <li><p>Why there is no error without explicit type for <code>map</code> callback. It is clear that <code>string[]</code> is not assignable to <code>Item[]</code>.</p>
  <pre class="lang-js prettyprint-override"><code>declare let foo: string[]
  declare let bar: Item[]
  
  foo = bar
  bar = foo
  </code></pre>
  </li>
  <li><p>Why does an error appear when I remove <code>WithVersion</code> from the <code>ResultType</code> definition? It looks like that intersection of <code>WithVersion</code> and <code>{ version: number list: Item[]; }</code> somehow affects <code>ResultType</code>, whereas in my opinion, this intersection should not affect it at all.</p>
  </li>
  </ol>
  <p><strong>SIMPLIFIED VERSION</strong></p>
  <pre class="lang-js prettyprint-override"><code>type Item = {
      id?: number
      name?: string
  }
  
  interface WithVersion {
      version: number
  }
  
  export type ResultType =
      &amp; WithVersion // #1 try to remove it
      &amp; {
          version: number
          list: Item[];
      };
  
  declare let result: ResultType;
  declare let list: string[];
  let a = {
      list,
      version: 2,
  };
  result = a;
  
  </code></pre>
  <p><a href="https://tsplay.dev/WYZ2vw" rel="noreferrer">Playground</a></p>
  <p>I have created an <a href="https://github.com/microsoft/TypeScript/issues/50608" rel="noreferrer">issue</a> in TS repo</p>