Search code examples
reactjstypescriptaxioseslinttypescript-eslint

Axios.delete(url[,config]): Type has no properties in common with type 'AxiosRequestConfig'


I use React, Typescript and Axios. I declare a class to be populated by static functions like this :

import axios from "axios"

export default class Users {

  static checkinByPassword(username: string, password: string){
    const params = {username, password}
    return axios.post(`/${this._key}/checkinbypassword`, params)
  }

  static delete(id: string){
    const params = {id: id}
    return axios.delete(`/${this._key}`, params)
  }
}

The first function (checkinByPassword) works fine. The second function make ESLint (I use ESLint for VSCode Editor) throwing an error :

Type '{ id: string; }' has no properties in common with type 'AxiosRequestConfig'.

screenshot in VSCode

What's AxiosRequestConfig ? and how do I make my params object to be compatible with it? Thank you in advance


Solution

  • axios.delete takes two argument, first is a url path and second is config.

    You need to wrap your params object another object which has a data property.

    For example:

    const config = {
      data: {
        id: "your id"
      }
    }
    
    axios.delete(url, config)...
    

    or

    const params = {id: id};
    
    axios.delete(url, {
      data: params
    })...