title: Typescript multiple object properties with shared types
body: <p>After some typescript studying and asking around i come up with the following shared object types declaration for multiple properties.</p>
  
  <ul>
  <li><strong>Question 1: is there simplier way to do it for multiple props wih shared types?</strong></li>
  <li><strong>Question 2: how to resolve last two examples?</strong></li>
  </ul>
  
  <p><a href="https://www.typescriptlang.org/play/?ssl=1&amp;ssc=1&amp;pln=49&amp;pc=2#code/C4TwDgpgBAysBOBLAdgcwArwPZgM5QF4oByZAQwFsJioAfE3AV3nKpvuIGMsAbLeYgChQkKADlGFAEYR4mHPiLEyqanRIALCIlQbgQwQHpDMRBTA9oIiMPDRT5y4SgBvKAG0A1hBBQUsBBQMbDwAXQAuKFxAtCgAXwBuQW5kaKgsKQArAEZIhwtoIhdBKFKoVghI4gBBVWR9ABoSsqYWSkqSGApEYA1iJrKobj54KvgIABMhOMEjQwB5MGBELHIeKGtbUUXl1bJ1oo9vX384JDR5MIB%20SOjz1HiklLSMzIAmSJ2VtediwYqqrUIPVprNjABhLDSFCTdJLb77DZ2LbQSHQ5Cww5eHx%20ZDiSQyOQhXChG7lAmyeJQABkUC%20ex4T1WLyyAGZImipDCJr9mqUASRqpYAB79PlQLQ6PSRN6CGZzKCXWSgJGiTgaMhoGzWAL3SEjZzoMjwZb7AA8ACUINx4BMzQBRYWcHiMCYQM0SaSyS64BokYb8YgAPj9yAp8CDNNcQ14-DJdyC8SDyWZwHSWQALHkYqh9fxeYMA6MSPBUFJQQqABJYADuGywUDIEx5mt8TYmPQR6zAxKgNZ6GigjGQnmQtbxx1wVxRUGqzc7DN%20Rx8txzESgUiwvAgmseKdSadeAFZPvDF7S5x3dj8inyi2My2Kyu2F2tIghGDZ5cYoNW68AGwgJ0XTdKAAE0oB7HAoAAM2wChG1VaAeEQbwNg0RApxnAANCDDmFVd7j9EBIjDL14D3Z5DyyAA2SJcILUoCJIMgpE4J9ShIqBsjlWYdWw5wrRtO1HWdV13Vwv1iBAYNQ3DZMqPTTIAHZ6Lw1w%20WY5Q2OmIA" rel="noreferrer">Typescript playground</a></p>
  
  <pre><code>type StringProps = 'name' | 'surname' | 'color'
  type NumberProps = 'age' | 'height'
  
  //Simple type
  type Simple = { [key in StringProps]: string };
  const obj1: Simple = {
      name: 'Agent',
      surname: 'Smith',
      color: 'red'
  }
  
  //Optional type
  type Optional = { [key in StringProps]?: string };
  const obj2: Optional = {
      name: 'Agent'
  }
  
  //Combined optional type
  type Combined = { [key in NumberProps]?: number } &amp; Optional;
  const obj3: Combined = {
      name: 'Alex',
      height: 2
  }
  
  // Property type change
  type StringColor = Partial&lt;Record&lt;Exclude&lt;NumberProps, 'color'&gt;, number&gt; &amp; { color?: string }&gt;
  const obj4: StringColor = {
      color: 'rgb'
  }
  
  // How to add any additional props with unknown keys?
  type Additional = { [key: string]: boolean };
  const obj5: Optional &amp; Additional = {
     color: 'rgb',
     additional: true
  }
  
  // How to exclude Y prop from a type like this?
  type XY = { x: string, y: number };
  const obj6: XY = {
     x: 'abc',
     y: 1
  }
  
  type X = Record&lt;Exclude&lt;XY, 'y'&gt;, number&gt;
  const obj7: XY = {
     x: 'abc'
  }
  </code></pre>