<p dir="auto">#### Summary</p>
<p dir="auto">The user code usually expects a specific type for the data returned from a request. currently however that metadata is lost and when using AxiosResponse and AxiosPromise we have to do casting.</p>
<p dir="auto">Here is how you could allow setting the type while not breaking backward compatibility:</p>
<p dir="auto">redefine the types:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="export interface AxiosResponse&lt;T = any&gt; {
  data: T;
  status: number;
  statusText: string;
  headers: any;
  config: AxiosRequestConfig;
}

export interface AxiosPromise&lt;TData = any&gt; extends Promise&lt;AxiosResponse&lt;TData&gt;&gt; {
}


export interface AxiosInstance {
/// ...redacted code
  request&lt;T = any&gt;(config: AxiosRequestConfig): AxiosPromise&lt;T&gt;;
  get&lt;T = any&gt;(url: string, config?: AxiosRequestConfig): AxiosPromise&lt;T&gt;;
  delete&lt;T = any&gt;(url: string, config?: AxiosRequestConfig): AxiosPromise&lt;T&gt;;
  head&lt;T = any&gt;(url: string, config?: AxiosRequestConfig): AxiosPromise&lt;T&gt;;
  post&lt;T = any&gt;(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise&lt;T&gt;;
  put&lt;T = any&gt;(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise&lt;T&gt;;
  patch&lt;T = any&gt;(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise&lt;T&gt;;
}"><pre class="notranslate"><code class="notranslate">export interface AxiosResponse&lt;T = any&gt; {
  data: T;
  status: number;
  statusText: string;
  headers: any;
  config: AxiosRequestConfig;
}

export interface AxiosPromise&lt;TData = any&gt; extends Promise&lt;AxiosResponse&lt;TData&gt;&gt; {
}


export interface AxiosInstance {
/// ...redacted code
  request&lt;T = any&gt;(config: AxiosRequestConfig): AxiosPromise&lt;T&gt;;
  get&lt;T = any&gt;(url: string, config?: AxiosRequestConfig): AxiosPromise&lt;T&gt;;
  delete&lt;T = any&gt;(url: string, config?: AxiosRequestConfig): AxiosPromise&lt;T&gt;;
  head&lt;T = any&gt;(url: string, config?: AxiosRequestConfig): AxiosPromise&lt;T&gt;;
  post&lt;T = any&gt;(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise&lt;T&gt;;
  put&lt;T = any&gt;(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise&lt;T&gt;;
  patch&lt;T = any&gt;(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise&lt;T&gt;;
}
</code></pre></div>
<p dir="auto">Now you can do this and get an error</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="let promise = axios.request&lt;{email:string}&gt;(config);
promise.then(res=&gt;{
    console.log('The user email is ' + res.data.eail); /// ERROR
});"><pre class="notranslate"><code class="notranslate">let promise = axios.request&lt;{email:string}&gt;(config);
promise.then(res=&gt;{
    console.log('The user email is ' + res.data.eail); /// ERROR
});
</code></pre></div>
<p dir="auto">I can look at the actual code (not the d.ts files) and make a pull request if you want.</p>
<p dir="auto">#### Context</p>
<ul dir="auto">
<li>axios version: 1.6</li>
<li>typescript &gt;= 2.3 (for the default generic type)</li>
</ul>
<p dir="auto">Hello,</p>
<p dir="auto">As axios automatically converts JSON responses could we get something like this:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="get&lt;T&gt;(url: string, config?: AxiosRequestConfig): AxiosPromise&lt;T&gt;;

export interface AxiosPromise&lt;T&gt; extends Promise&lt;AxiosResponse&lt;T&gt;&gt; {
}

export interface AxiosResponse&lt;T&gt; {
  data: T;
  status: number;
  statusText: string;
  headers: any;
  config: AxiosRequestConfig;
}"><pre class="notranslate"><span class="pl-s1">get</span><span class="pl-c1">&lt;</span><span class="pl-smi">T</span><span class="pl-c1">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">url</span>: <span class="pl-smi">string</span><span class="pl-kos">,</span> <span class="pl-s1">config</span>?: <span class="pl-smi">AxiosRequestConfig</span><span class="pl-kos">)</span>: <span class="pl-smi">AxiosPromise</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">;</span>

<span class="pl-k">export</span> <span class="pl-k">interface</span> <span class="pl-smi">AxiosPromise</span><span class="pl-c1">&lt;</span><span class="pl-smi">T</span><span class="pl-c1">&gt;</span> <span class="pl-k">extends</span> <span class="pl-smi">Promise</span><span class="pl-kos">&lt;</span><span class="pl-smi">AxiosResponse</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
<span class="pl-kos">}</span>

<span class="pl-k">export</span> <span class="pl-k">interface</span> <span class="pl-smi">AxiosResponse</span><span class="pl-c1">&lt;</span><span class="pl-smi">T</span><span class="pl-c1">&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-c1">data</span>: <span class="pl-smi">T</span><span class="pl-kos">;</span>
  <span class="pl-c1">status</span>: <span class="pl-smi">number</span><span class="pl-kos">;</span>
  <span class="pl-c1">statusText</span>: <span class="pl-smi">string</span><span class="pl-kos">;</span>
  <span class="pl-c1">headers</span>: <span class="pl-smi">any</span><span class="pl-kos">;</span>
  <span class="pl-c1">config</span>: <span class="pl-smi">AxiosRequestConfig</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>