Argument of type 'AxiosDefaults' is not assignable to parameter of type 'CreateAxiosDefaults<any>' #5737
Closed
rogue-wild
started this conversation in
General
Replies: 1 comment 3 replies
-
Change line 18 to,
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
` import axios, { AxiosInstance, AxiosResponse } from "axios";
interface Post {
userId: number;
id: number;
title: string;
body: string;
}
interface AxiosDefaults {
baseURL: string;
}
const baseURL: AxiosDefaults = {
baseURL: "https://jsonplaceholder.typicode.com",
};
const api: AxiosInstance = axios.create(baseURL);
api.interceptors.response.use(
(response) => response,
(error) => {
console.log(error);
throw error;
}
);
export const fetchPost = async (postId: number): Promise => {
try {
const response: AxiosResponse = await api.get(
/posts/${postId}
);const post = response.data;
return post;
} catch (error) {
console.log(error);
throw error;
}
};
`
I'm getting a error in this can anyone help please?
Argument of type 'AxiosDefaults' is not assignable to parameter of type 'CreateAxiosDefaults'.
Property 'string' is missing in type 'AxiosDefaults' but required in type 'CreateAxiosDefaults'.
16 | };
17 |
18 | const api: AxiosInstance = axios.create(baseURL);
| ^^^^^^^
19 | api.interceptors.response.use(
20 | (response) => response,
21 | (error) => {
Beta Was this translation helpful? Give feedback.
All reactions