title: Typescript keep order or the returned values type in case of mapped object
body: <p>I'm working on simple mapper of at object. It should accept an array of the object properties and return an array of the values of these properties.
  It works fine, but in case of Typescript I couldn't save the type order of the returned values. </p>
  
  <p>Here is the example</p>
  
  <pre><code>import { createStore, Store as FriendsStore } from "./mobx_react_lite_store";
  import { createAccountsStore, AccountsStoreType } from "./accountsStoreLite";
  
  type RootObj = {
      friendsStore: FriendsStore,
      accountsStore: AccountsStoreType
  };
  
  const rootStore: RootObj = {
      friendsStore: friendsStore,
      accountsStore: accountsStore
  };
  
  function pickStores&lt;T, K extends keyof T&gt;(rootStore: T, keys: K[]): T[K][] {
      return keys.map((key: K) =&gt; {
          const store = rootStore[key];
  
          if (!store) {
              throw new Error(`Can't find the store with name ${key} in rootStore. Myabe yo've forgottent
              to add this store to the rootStore.`);
          }
  
          return store;
      }) 
  }
  </code></pre>
  
  <p>When I'm trying to call it with only single store, it works like a charm
  for ex</p>
  
  <pre><code>// Works fine. It shows that accountsStore has AccountsStoreType
  const [ accountsStore ] = pickStores(rootStore, ["accountsStore"]);
  
  // Works fine. It shows that accountsStore has friendsStore type
  const [ friendsStore ] = pickStores(rootStore, ["friendsStore"]);
  </code></pre>
  
  <p>but when I'm trying to call it with 2 store the returned types don't keep some order.
  So <code>friendsStore</code> could be EITHER friendsStore or AccountsStoreType. The same for <code>accountsStore</code></p>
  
  <pre><code>const [ friendsStore, accountsStore ] = pickStores(rootStore, ["friendsStore", "accountsStore"]);
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/pfnvh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pfnvh.png" alt="Here is the screenshot"></a></p>
  
  <p>Is it possible to save the correct <strong>Type</strong> for <strong>each</strong> destructed property?
  Thanks for any help.</p>
  
  <p><strong>UPDATE</strong>
  <em>lukasgeiter</em> provided the correct answer but there were few interesting tricks for Typescript.  I've investigated them, looked for some documentation etc. and here are the useful resources to understand those features:</p>
  
  <p>Hope this info will help someone.</p>
  
  <p><a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" rel="nofollow noreferrer">About typle</a></p>
  
  <p><a href="https://github.com/Microsoft/TypeScript/pull/13604" rel="nofollow noreferrer">Allow deriving from object and intersection types</a></p>
  
  <p><a href="https://mariusschulz.com/blog/keyof-and-lookup-types-in-typescript" rel="nofollow noreferrer">About lookup types</a></p>
  
  <p><a href="https://mariusschulz.com/blog/mapped-types-in-typescript" rel="nofollow noreferrer">About mapped types</a></p>