Reputation: 1591
I am trying to make an axios call but getting an error shown below. Using vue 3/ vite/ typescript for my project. In my IDE params is underlined and highlighted red. The code does work but wont build.
My Axios call
import axios from "axios";
async userstatusconfirmed() { let url = "/auth/amiconfirmed"; let headers = authHeader(); let params = {withCredentials: true} await axios.get(url, {params, headers} ).then((response) => { if (response.status == 200) { if (response.data.confirmed == true) { this.$router.push({ name: "home" }); } } }); },
TS2345: Argument of type '{ params: { withCredentials: boolean; }; headers: Record<string, string>; }' is not assignable to parameter of type 'AxiosRequestConfig<any>'. Object literal may only specify known properties, and 'params' does not exist in type 'AxiosRequestConfig<any>'.
Upvotes: 0
Views: 330
Reputation: 90068
The types error you're getting is weird (I can't repro it, using axios 0.27.2
).
You might want to create a runnable mcve on codesandbox.io or similar.
However, withCredentials
is an AxiosRequestConfig member, it doesn't go inside params
:
userstatusconfirmed() {
const url = "/auth/amiconfirmed";
const config = {
headers: authHeader(),
withCredentials: true
};
return axios.get(url, config)
.then(/* ... */);
}
Upvotes: 1