Type 'AxiosStatic' is missing the following properties from type 'AxiosStatic': cancel, cancelAll

91 Views Asked by At

http.ts file is as follows

// using axios as current Http library
import axios from 'axios';
import axiosCancel from 'axios-cancel';

// add `cancel` prototype method to abort `XHR` requests and promise
axiosCancel( axios );

export const Http = {};

/*************************************************************/

// HTTP execute method
// use this execute method to execute the axios request
Http.execute = ( config ) => {
    return axios( config );
};

// HTTP Cancel method
// use Http.cancel method to cancel request with the id
Http.cancel = ( id ) => {
    return new axios.Cancel(id);
};

// HTTP CancelAll method
// Use Http.cancelAll to cancel all the ongoing requests
Http.cancelAll = () => {
    return axios.cancelAll();
};

I'm getting this error while hovering over this line >>> axiosCancel( axios );

Argument of type 'import("/Users/wasim.akram/Desktop/Udemy/select-and-share-place/node_modules/axios/index").AxiosStatic' is not assignable to parameter of type 'import("/Users/wasim.akram/Desktop/Udemy/select-and-share-place/node_modules/@types/axios-cancel/node_modules/axios/axios").AxiosStatic'. Type 'AxiosStatic' is missing the following properties from type 'AxiosStatic': cancel, cancelAll

Getting this on hovering over this line >> return axios.cancel( id );

Property 'cancel' does not exist on type 'AxiosStatic'. Did you mean 'Cancel'?ts(2551) index.d.ts(528, 3): 'Cancel' is declared here.

Getting this on hovering over this line >> return axios.cancelAll();

Property 'cancel' does not exist on type 'AxiosStatic'. Did you mean 'Cancel'?ts(2551) index.d.ts(528, 3): 'Cancel' is declared here.

NPM dependencies with their version

"devDependencies": {
    "@types/axios": "^0.14.0",
    "@types/axios-cancel": "^0.2.2",
    "ts-loader": "^9.4.4",
    "typescript": "^5.2.2",
    "webpack": "^5.88.2",
    "webpack-cli": "^5.1.4",
    "webpack-dev-server": "^4.15.1"
  },
  "dependencies": {
    "axios": "^1.5.1",
    "axios-cancel": "^0.2.2"
  }
0

There are 0 best solutions below