13

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

DennyHiu
  • 4,861
  • 8
  • 48
  • 80

1 Answers1

14

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
})...
Tazo leladze
  • 1,430
  • 1
  • 16
  • 27
  • well... it's work! But here: https://github.com/axios/axios#note they said that `When using the alias methods url, method, and data properties don't need to be specified in config`. As far as I know, the .delete() method is one of the alias – DennyHiu Mar 02 '20 at 07:58
  • 1
    Mm.. Yes. Maybe you are right or the author wanted to say something else.. BTW i suggest you continue coding. – Tazo leladze Mar 02 '20 at 10:01