title: Conditional response type
body: <p>I'm trying to create a function that will return me a <code>Response&lt;T&gt;</code> when I provide a value on its argument, and <code>Response&lt;string&gt;</code> when I don't. The return type that I have works for me, the issue is I'm getting errors on both response statements saying I'm not returning the correct type.</p>
  
  <pre><code>interface ResponseOverride&lt;Value&gt; {
    value?: Value;
    onChange?(): void;
  }
  
  interface Response&lt;T&gt; {
    value: T;
    onChange(): void;
  }
  
  function getResponse&lt;T, K extends ResponseOverride&lt;T&gt;&gt;({
    value: overrideValue,
    ...overrides
  }: K): K extends {value: T} ? Response&lt;T&gt; : Response&lt;string&gt; {
    const defaults = {
      onChange:() =&gt; {},
    };
  
    if (overrideValue !== undefined) {
      return {...defaults, ...overrides, value: overrideValue};
    }
  
    return {...defaults, ...overrides, value: ''};
  }
  </code></pre>
  
  <p>How can I achieve this without having to do something like <code>return {...} as any;</code>?</p>
  
  <p><a href="https://www.typescriptlang.org/play/?ssl=1&amp;ssc=1&amp;pln=24&amp;pc=2#code/JYOwLgpgTgZghgYwgAgEoQM4AcD2IMQDyAbtFMACYQA8AanADYCuEAfMgN4CwAUMssUYsA-AC5k9ZhADcvfngDCACzggA5hGEAKAJTjiOSrJ4BfXr1CRYiFOmx4CAQWoAVdtz4ChEcS+PyQZVUNXX1DCmMzHl4YJhAEMGA8ZA0wO1x8GhcAGmQAaWQIAA9IEAoMNEwMghIySizWVi0PfkEpcRxSKHIqSRZsuWQAOhHOuqoMXhNxPL18wpKIMoqONpZfE2RhSvtM5zdkcXSHCGcMMHJ1d0GEBzBkKngmBjAKgF5OQYCg9R9kXWQb3cJgGnhMxkGwBg-zG3XqfRQAEI3h84o9QBAKDpPp5+FAIGAmFAQJwRkNHnBnq9cmTYT1MLk1n86fDvODBlFBvjCcTSSMKVSMDTRl16UKvO1kAByKXs0xAA" rel="nofollow noreferrer">Playground link</a></p>