2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-11 18:02:32 +03:00

Test types (#4140)

* Distinguish request and response data types

* Fix Axios headers type

`axios.headers` is not of the same type as `request.headers`, so a new type
`AxiosDefaults` was introduced

* Replace grunt-ts with dtslint

This asserts that the type definitions are valid in the specified TypeScript
version and above. This is the same tool that is used by DefinitelyTyped.

* Remove grunt-ts

* Restore typescript dependency

* Fix missing semicolons

Co-authored-by: Claas Augner <github@caugner.de>
Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Remco Haszing
2021-10-12 09:53:10 +02:00
committed by GitHub
parent fce210a67e
commit 94a9344799
6 changed files with 58 additions and 31 deletions
+5 -5
View File
@@ -8,7 +8,7 @@ import axios, {
CancelToken,
CancelTokenSource,
Canceler
} from '../../';
} from 'axios';
const config: AxiosRequestConfig = {
url: '/user',
@@ -170,8 +170,8 @@ axios.patch<User>('/user', { name: 'foo', id: 1 })
// (Typed methods) with custom response type
const handleStringResponse = (response: string) => {
console.log(response)
}
console.log(response);
};
axios.get<User, string>('/user?id=12345')
.then(handleStringResponse)
@@ -342,11 +342,11 @@ axios.get('/user')
axios.get('/user')
.catch((error: any) => 'foo')
.then((value: string) => {});
.then((value) => {});
axios.get('/user')
.catch((error: any) => Promise.resolve('foo'))
.then((value: string) => {});
.then((value) => {});
// Cancellation