question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

something about the AxiosRequestConfig interface

See original GitHub issue

#### Summary

I want the AxiosRequestConfig interface to be this:

{
  url?: string;
  method?: string;
  baseURL?: string;
  transformRequest?: AxiosTransformer | AxiosTransformer[];
  transformResponse?: AxiosTransformer | AxiosTransformer[];
  headers?: any;
  params?: any;
  paramsSerializer?: (params: any) => string;
  data?: any;
  timeout?: number;
  withCredentials?: boolean;
  adapter?: AxiosAdapter;
  auth?: AxiosBasicCredentials;
  responseType?: string;
  xsrfCookieName?: string;
  xsrfHeaderName?: string;
  onUploadProgress?: (progressEvent: any) => void;
  onDownloadProgress?: (progressEvent: any) => void;
  maxContentLength?: number;
  validateStatus?: (status: number) => boolean;
  maxRedirects?: number;
  httpAgent?: any;
  httpsAgent?: any;
  proxy?: AxiosProxyConfig | false;
  cancelToken?: CancelToken;
  // custom config
  [someOtherConfig: string]: any;
}

So i can add some custom config without type matching error

#### Context

  • axios version: e.g.: v0.17.1

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

7reactions
klummycommented, Jan 8, 2018

I will recommend a customConfig: object | null property to be added to the interface which allows users to add unlimited custom configuration without type errors.

I am open submitting a PR for this if the community deems it necessary.

2reactions
Helaerscommented, Mar 25, 2019

Any update on this?

Edit Those seeking a solution. Create your own axios.d.ts file and put it in the root of your project.

// axios.d.ts
import * as axios from 'axios';

declare module 'axios' {
  export interface AxiosTransformer {
    (data: any, headers?: any): any;
  }

  export interface AxiosAdapter {
    (config: AxiosRequestConfig): AxiosPromise<any>;
  }

  export interface AxiosBasicCredentials {
    username: string;
    password: string;
  }

  export interface AxiosProxyConfig {
    host: string;
    port: number;
    auth?: {
      username: string;
      password: string;
    };
  }

  export interface AxiosRequestConfig {
    url?: string;
    method?: string;
    baseURL?: string;
    transformRequest?: AxiosTransformer | AxiosTransformer[];
    transformResponse?: AxiosTransformer | AxiosTransformer[];
    headers?: any;
    params?: any;
    paramsSerializer?: (params: any) => string;
    data?: any;
    timeout?: number;
    withCredentials?: boolean;
    adapter?: AxiosAdapter;
    auth?: AxiosBasicCredentials;
    responseType?: string;
    xsrfCookieName?: string;
    xsrfHeaderName?: string;
    onUploadProgress?: (progressEvent: any) => void;
    onDownloadProgress?: (progressEvent: any) => void;
    maxContentLength?: number;
    validateStatus?: (status: number) => boolean;
    maxRedirects?: number;
    httpAgent?: any;
    httpsAgent?: any;
    proxy?: AxiosProxyConfig | false;
    cancelToken?: CancelToken;
    // custom config
    [someOtherConfig: string]: any;
  }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Axios typescript customize AxiosRequestConfig - Stack Overflow
You can extend any library types, by using the typescript decleration merging feature. (docs). So this should do the job:
Read more >
Interface: AxiosRequestConfig<D\> - Medusa
Properties​ · adapter​ · auth​ · baseURL​ · cancelToken​ · data​ · decompress​ · headers​ · httpAgent​.
Read more >
Retry API Call Axios Interceptor - StackBlitz
Blank starter project for building TypeScript apps.
Read more >
resulting typing of axios from index.d.ts is incorrect : WEB-32066
export interface AxiosInstance { (config: AxiosRequestConfig): AxiosPromise; (url: string, config?: AxiosRequestConfig): AxiosPromise; defaults: ...
Read more >
How to Perform HTTP Requests with Axios – A Complete Guide
Sending multiple requests with this interface, on the other hand, ... axios.request(config) axios.get(url[, config]) axios.delete(url[, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found