title: How to determine the type of object with possible and string and numeric indices in typescript?
body: <p>My function can work with array and objects. Objects have keys with string-type and array have keys with numeric-type. Also there can be object without keys.</p>
  
  <p>I determine two interfaces and one type:</p>
  
  <pre><code>interface IObjectStringKey {
    [key: string]: any
  }
  interface IObjectNumberKey {
    [key: number]: any
  }
  // object with key-string, key-number or without key
  type IObjectAnyKey = IObjectNumberKey | IObjectStringKey | {};
  </code></pre>
  
  <p>My function get argument - array of this type and I want to iterate through every key of every object.</p>
  
  <pre><code>function myFunction( ...sources: IObjectAnyKey[]) {
          const values = [];
  for (let i = 0; i &lt; sources.length; i++) {
      const source: IObjectAnyKey = sources[i];
          for (let key in source) {
              const val = source[key];
          }
      }
  }
  </code></pre>
  
  <p>You can see error in playground: <a href="https://www.typescriptlang.org/play/index.html#src=interface%20IObjectStringKey%20%7B%0D%0A%20%20%5Bkey%3A%20string%5D%3A%20any%0D%0A%7D%0D%0Ainterface%20IObjectNumberKey%20%7B%0D%0A%20%20%5Bkey%3A%20number%5D%3A%20any%0D%0A%7D%0D%0A%2F%2F%20object%20with%20key-string%2C%20key-number%20or%20without%20key%0D%0Atype%20IObjectAnyKey%20%3D%20IObjectNumberKey%20%7C%20IObjectStringKey%20%7C%20%7B%7D%3B%0D%0A%0D%0Afunction%20myFunction(%20...sources%3A%20IObjectAnyKey%5B%5D)%20%7B%0D%0A%20%20%20%20const%20values%20%3D%20%5B%5D%3B%0D%0A%20%20%20%20for%20(let%20i%20%3D%200%3B%20i%20%3C%20sources.length%3B%20i%2B%2B)%20%7B%0D%0A%20%20%20%20%20%20%20%20const%20source%3A%20IObjectAnyKey%20%3D%20sources%5Bi%5D%3B%0D%0A%20%20%20%20%20%20%20%20for%20(let%20key%20in%20source)%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20val%20%3D%20source%5Bkey%5D%3B%0D%0A%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%7D%0D%0A%7D" rel="nofollow noreferrer">typescript.org/myTask</a> <strong>(you need to enable 'noImplicitAny' in Options)</strong></p>
  
  <p><a href="https://i.stack.imgur.com/8q8Lc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8q8Lc.png" alt="enter image description here"></a></p>
  
  <p>Error is "Element implicitly has an 'any' type because type 'IObjectAnyKey' has no index signature". How can I solve this problem? I need to know how to define type with different index type. Or, maybe, there is some other solve.</p>