Skip to content

breaking interface change #4109

@andrei9669

Description

@andrei9669

Describe the bug

In #2995 merge request, there was introduced a bug.

There came 2 issues.

  1. input and output types have to be the same.
  2. existing usages are broken

To Reproduce

pass input and output type to axios.post

interface Input {
  name: string;
}
interface Output {
  value: string;
}
/* existing usages are broken
 * TS2345: Argument of type '{ name: string; }' is not assignable to parameter of type 'undefined'.
 */
const { data } = await axios.post<Output>('url', {
  name: 'hello',
});
/* Input and output have to be the same type
 * TS2345: Argument of type '{ name: string; }' is not assignable to parameter of type 'AxiosResponse<Output>'.   
 * Object literal may only specify known properties, and 'name' does not exist in type 'AxiosResponse<Output>'.
 */
const { data } = await axios.post<Input, AxiosResponse<Output>>('url', {
  name: 'hello',
});

Expected behavior

No type errors.

Environment

  • Axios Version 0.22.0
  • Adapter HTTP
  • Browser Chrome
  • Browser Version 94.0.4606.61
  • Node.js Version v14.17.5
  • OS: Windows 10
  • Additional Library Versions none

Additional context/Screenshots

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions