diff --git a/types/refresh-fetch/index.d.ts b/types/refresh-fetch/index.d.ts new file mode 100644 index 0000000000..1f904f5206 --- /dev/null +++ b/types/refresh-fetch/index.d.ts @@ -0,0 +1,19 @@ +// Type definitions for refresh-fetch 0.6 +// Project: https://github.com/vlki/refresh-fetch +// Definitions by: Alex Lisenkov +// Pieter Braam +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +export function configureRefreshFetch( + configuration: { + fetch: T; + refreshToken: () => Promise; + shouldRefreshToken: (error: any) => boolean; + }): T; + +export function fetchJSON(url: string | Request | URL, options?: object): Promise<{ + /* tslint:disable-next-line no-unnecessary-generics */ + body: ResponseBody; + response: Response; +}>; diff --git a/types/refresh-fetch/refresh-fetch-tests.ts b/types/refresh-fetch/refresh-fetch-tests.ts new file mode 100644 index 0000000000..17f6aefb84 --- /dev/null +++ b/types/refresh-fetch/refresh-fetch-tests.ts @@ -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 => { + return fetchJSON<{ + refreshToken: string; + }>( + 'url', + {}, + ).then(() => { + return; + }); +}; + +const fetch = configureRefreshFetch({ + fetch: fetchJSONWithToken, + shouldRefreshToken: (): boolean => true, + refreshToken, +}); diff --git a/types/refresh-fetch/tsconfig.json b/types/refresh-fetch/tsconfig.json new file mode 100644 index 0000000000..5fab45b7a9 --- /dev/null +++ b/types/refresh-fetch/tsconfig.json @@ -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" + ] +} diff --git a/types/refresh-fetch/tslint.json b/types/refresh-fetch/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/refresh-fetch/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}