I am encountering an issue where I need to specify both the JSON body and the response type separately, as they are different. Some examples I've seen have them set to be the same.
Here is the error message I received:
Argument of type '{ grant_type: string; refresh_token: string; }' is not assignable to parameter of type 'AuthResponse'. Object literal may only specify known properties, and 'grant_type' does not exist in type 'AuthResponse'.
This is the response type I defined:
export interface AuthResponse {
token: string;
token_type: string;
access_token: string;
access_token_expires_at: string;
refresh_token: string;
refresh_token_expires_at: string;
}
My use of axios:
axios
.post<AuthResponse>(
secrets.authURL,//Defined in enclosing class
{
grant_type: this.grantType,//Defined in enclosing class
refresh_token: this.authPayload,//Defined in enclosing class
},//<-- Defined as data and conflicts with AuthResponse
{
headers: {
Authorization: this.getAuthHeader(),//Defined in enclosing class
"Content-Type": this.contentType,///Defined in enclosing class
},
}
)
.then((axiosResp) => {
const response = axiosResp.data;//<-- Not the type I'd expect
});
axiosResp.data
is of type
{grant_type: ..., refresh_token: ...}
instead of AuthResponse
.
Based on various JavaScript samples, the data should be for the request body, but it seems like it's being incorrectly interpreted as the response type. There might be something fundamentally wrong that I'm doing.
Edit/Answer: As indicated by @jrsharpe's comment, this turns out to be a bug. A fix has been released in v0.23.0 just a few hours ago. This update addresses the bug #4116. Upgrading to version 0.23.0 or higher should resolve the issue.