How to set axiosconfig using typescript?

Issue

I am new in Typescript. I am converting my code from JavaScript to Typescript. My code below will work in JavaScript, but it has an error in Typescript

import axios from "axios";

const data = JSON.stringify([eventID]);

const config = {
    method: "delete",
    url: url,
    headers: { 
        "Authorization": `Bearer ${elasticPrivateKey}`, 
        "Content-Type": "application/json",
    },
    data: data,
};

return axios(config);

I have an error like this

enter image description here

I don’t understand how to get and configure this AxiosRequestConfig

Solution

I am not sure but try this

import axios,{ AxiosRequestConfig } from 'axios';

const config:AxiosRequestConfig = {
        method: "delete",
        url: url,
        headers: { 
            "Authorization": `Bearer ${elasticPrivateKey}`, 
            "Content-Type": "application/json",
        },
        data: data,
    };

Answered By – user14433996

Answer Checked By – Cary Denson (AngularFixing Admin)

Leave a Reply

Your email address will not be published.