Currently utilizing Vue 3, Vite, Axios, and TypeScript. While my function functions properly in development, it throws an error in my IDE and during the build process.
get count() {
axios({
method: "get",
url: "/info/count",
headers: authHeader(),
})
.then((response) => {
this.count = response.data.status;
});
},
Error showing up in PyCharm IDE
TS2769: No overload matches this call. Overload 1 of 2, '(config: AxiosRequestConfig<any>): AxiosPromise<any>', displayed the following error. Argument of type '{ method: "get"; url: string; headers: { Authorization: string; } | { Authorization?: undefined; }; }' is not assignable to parameter of type 'AxiosRequestConfig<any>'. Object literal may only specify known properties, and 'headers' does not exist in type 'AxiosRequestConfig<any>'. Overload 2 of 2, '(url: string, config?: AxiosRequestConfig<any>): AxiosPromise<any>', showed the following error. Argument of type '{ method: string; url: string; headers: { Authorization: string; } | { Authorization?: undefined; }; }' is not assignable to parameter of type 'string
Content within AuthHeader()
export default function authHeader () {
let user_token = localStorage.getItem('auth_user')
let auth_token = localStorage.getItem('auth_token')
if (user_token && auth_token) {
return { 'Authorization': 'bearer ' + auth_token };
} else {
return {};
}
}