mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-02-03 23:42:50 +00:00
Add refresh-fetch types (#42308)
* added typings for refresh-fetch * fixed lint errors * small fixes
This commit is contained in:
parent
eb2cc4bdd4
commit
7d8d231ee5
19
types/refresh-fetch/index.d.ts
vendored
Normal file
19
types/refresh-fetch/index.d.ts
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
// Type definitions for refresh-fetch 0.6
|
||||
// Project: https://github.com/vlki/refresh-fetch
|
||||
// Definitions by: Alex Lisenkov <https://github.com/AlexLisenkov>
|
||||
// Pieter Braam <https://github.com/ppbraam>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
export function configureRefreshFetch<T>(
|
||||
configuration: {
|
||||
fetch: T;
|
||||
refreshToken: () => Promise<void>;
|
||||
shouldRefreshToken: (error: any) => boolean;
|
||||
}): T;
|
||||
|
||||
export function fetchJSON<ResponseBody>(url: string | Request | URL, options?: object): Promise<{
|
||||
/* tslint:disable-next-line no-unnecessary-generics */
|
||||
body: ResponseBody;
|
||||
response: Response;
|
||||
}>;
|
||||
22
types/refresh-fetch/refresh-fetch-tests.ts
Normal file
22
types/refresh-fetch/refresh-fetch-tests.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { configureRefreshFetch, fetchJSON } from 'refresh-fetch';
|
||||
|
||||
const fetchJSONWithToken = (url: string, options?: RequestInit): Promise<{ body: {}; response: Response }> => {
|
||||
return fetchJSON(url, options);
|
||||
};
|
||||
|
||||
const refreshToken = (): Promise<void> => {
|
||||
return fetchJSON<{
|
||||
refreshToken: string;
|
||||
}>(
|
||||
'url',
|
||||
{},
|
||||
).then(() => {
|
||||
return;
|
||||
});
|
||||
};
|
||||
|
||||
const fetch = configureRefreshFetch({
|
||||
fetch: fetchJSONWithToken,
|
||||
shouldRefreshToken: (): boolean => true,
|
||||
refreshToken,
|
||||
});
|
||||
24
types/refresh-fetch/tsconfig.json
Normal file
24
types/refresh-fetch/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"refresh-fetch-tests.ts"
|
||||
]
|
||||
}
|
||||
3
types/refresh-fetch/tslint.json
Normal file
3
types/refresh-fetch/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user