title: Writing a function that picks values from an object and return the correct types
body: <p>I have a function that pulls a value based on the string you give it. When I execute the function how do I make the output of the function typed to the value it has pulled out.</p>
  <pre><code>const config = {
    one: 'one-string',
    two: 'two-string',
    three: true,
    four: {
      five: 'five-string',
      six: false
    },
    seven: [
      'eight', 'nine', 'ten'
    ]
  }
  
  type Config = {
    one: string;
    two: string;
    three: boolean;
    four: {
      five: string;
      six: boolean;
    }
    seven: string[]
  }
  
  type GetConfig = (key: keyof Config) =&gt; Config[keyof Config];
  
  export const getConfig: GetConfig = key =&gt; {
    return config[key];
  };
  
  getConfig('seven').map(...);
  </code></pre>
  <p>Currently I get the following error:</p>
  <blockquote>
  <p>Property 'map' does not exist on type 'string | boolean | string[] | {
  five: string; six: boolean; }'.   Property 'map' does not exist on
  type 'string'.</p>
  </blockquote>
  <p>because <code>getConfig</code> isn't being typed as an array as it is indicated above rather it's just being typed as any one of the possible types.</p>