Add refresh-fetch types (#42308)

* added typings for refresh-fetch

* fixed lint errors

* small fixes
This commit is contained in:
ppbraam 2020-02-12 19:45:29 +01:00 committed by GitHub
parent eb2cc4bdd4
commit 7d8d231ee5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 0 deletions

19
types/refresh-fetch/index.d.ts vendored Normal file
View 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;
}>;

View 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,
});

View 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"
]
}

View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}