From 7d8d231ee53d4bcdf7c8a9067fff966d92ebf342 Mon Sep 17 00:00:00 2001 From: ppbraam Date: Wed, 12 Feb 2020 19:45:29 +0100 Subject: [PATCH] Add refresh-fetch types (#42308) * added typings for refresh-fetch * fixed lint errors * small fixes --- types/refresh-fetch/index.d.ts | 19 +++++++++++++++++ types/refresh-fetch/refresh-fetch-tests.ts | 22 ++++++++++++++++++++ types/refresh-fetch/tsconfig.json | 24 ++++++++++++++++++++++ types/refresh-fetch/tslint.json | 3 +++ 4 files changed, 68 insertions(+) create mode 100644 types/refresh-fetch/index.d.ts create mode 100644 types/refresh-fetch/refresh-fetch-tests.ts create mode 100644 types/refresh-fetch/tsconfig.json create mode 100644 types/refresh-fetch/tslint.json 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" +}