title: Dynamic Typescript Object Properties from Function Arguments
body: <p>I have a function that takes in a <em>n</em> number of arguments, and generates a new object containing a key-value map of the arguments to a unique hash.</p>
  
  <p>Is there a way for Typescript to dynamically infer the keys of the returned object from the arguments of the function?</p>
  
  <hr>
  
  <p>Example,</p>
  
  <p>CreateActionType function that generates the dictionary:</p>
  
  <pre><code>function createActionType&lt;K extends {} | void&gt;(...type: string[]): Readonly&lt;{ [key: string]: string }&gt; {
      const actions = {};
  
      type.forEach((item: string) =&gt; {
          actions[item] = `${item}/${generateUniqueId()}`;
      });
  
      return Object.freeze(actions);
  };
  </code></pre>
  
  <p>Using createActionType:</p>
  
  <pre><code>interface ActionTypes {
      MY_ACTION_1, 
      MY_ACTION_2
  }
  
  const action = createActionType&lt;ActionTypes&gt;("MY_ACTION_1", "MY_ACTION_2");
  /*
   * action contains { MY_ACTION_1: "MY_ACTION_1/0", MY_ACTION_2: "MY_ACTION_2/1" }
   */
  action.MY_ACTION_1; // returns "MY_ACTION_1/0"
  </code></pre>
  
  <p>I would like to remove the duplication, and just call createActionType like:</p>
  
  <pre><code>const action = createActionType("MY_ACTION_1", "MY_ACTION_2");
  action.MY_ACTION_1;  // Intellisense will be able to infer the properties 
                       // MY_ACTION_1 and MY_ACTION_2 from action
  </code></pre>