title: Typescript merge two interfaces
body: <blockquote>
  <p><em><strong>UPDATE</strong></em> <br>
  <strong>i found this solution</strong></p>
  <pre><code>type Merge&lt;T, U&gt; = {
    [K in keyof T | keyof U]: K extends keyof U? U[K]: K extends keyof T? T[K]: never;
  };
  </code></pre>
  </blockquote>
  <p>is there something like this in typescript?(spread operator)</p>
  <pre><code>type Merge&lt;T, U&gt; = ...[K in keyof T]: T[K], ...[K in keyof U]: U[K]
  </code></pre>
  <p><strong>my task is to Merge two types into a new type. Keys of the second type overrides keys of the first type.</strong>
  for example:</p>
  <pre><code>interface User {
    id: string;
    name: string;
    age: number;
    role: &quot;admin&quot; | &quot;moderator&quot; | &quot;user&quot;;
    occupation: string;
  }
  interface User2 {
    id: string;
    name: string;
    age: boolean;
  }
  
  type mergedType = Merge&lt;User, User2&gt;
  </code></pre>
  <p>after merge, interface type will be something like this-&gt;</p>
  <pre><code>{
    id: string;
    name: string;
    age: boolean;
    role: &quot;admin&quot; | &quot;moderator&quot; | &quot;user&quot;;
    occupation: string;
  }
  </code></pre>