title: Deserialize axios response based on the generic type
body: <p>In my code, I'm using <a href="https://github.com/mpyw/axios-case-converter" rel="nofollow noreferrer">axios-case-converter</a> for the automatic snake -&gt; camel case conversion. Also, I have the endpoint that returns JSON or text based on the requested mime type. I need to be able to deserialize or keep it as a string based on the generic and the mime type.</p>
  <p>The code is supposed to look something like this:</p>
  <pre><code>type Format = 'json' | 'text';
  interface MyType {}
  
  const get = &lt;
                T extends string | MyType = string,
                TFormat extends Format = 'json',
                // If TFormat = 'json' + T = MyType =&gt; MyType
                // T = string =&gt; string
                TOutput = T extends MyType
                  ? (TFormat extends 'json' : never)
                  : string,
                TDeserialize = TOutput extends MyType ? true : false
              &gt;(format: TFormat, deserialize?: TDeserialize) =&gt; {
    return axios.get&lt;TOutput&gt;('&lt;url&gt;', transformResponse: res =&gt; {
      if (!deserialize) return res;
      return axios.defaults.transformResponse;
    });
  }
  </code></pre>
  <p>Is there any way to write it more human-readable?</p>