Reputation: 13
const handleSubmit = () => {
axios({
method: changeMethod,
url: changeSubmitValue,
responseType: 'stream'
}).then(function(response) {
console.log(response);
});
};
There is an axios typescript error as above.
The axios method changes according to the changeMethod
state value.
index.d.ts(48, 2): The expected type comes from property'method' which is declared here on type'AxiosRequestConfig'
To get rid of this error, I need some help on where to type declaration in axios.
Upvotes: 1
Views: 533
Reputation: 1155
How about fix like this union type.
Hello Korea people : )
import {Method} from "axios";
...
const handleSubmit = () => {
axios({
method: changeMethod as Method,
url: changeSubmitValue,
responseType: 'stream'
}).then(function(response) {
console.log(response);
});
};
Upvotes: 3