diff --git a/src/components/Search/Search.tsx b/src/components/Search/Search.tsx index 0143284d9..67d049c8e 100644 --- a/src/components/Search/Search.tsx +++ b/src/components/Search/Search.tsx @@ -139,7 +139,6 @@ export class Search extends Component, State> { */ private handleFetchPackages: handleFetchPackages = async ({ value }) => { try { - // @ts-ignore const controller = new window.AbortController(); const signal = controller.signal; // Keep track of search requests. diff --git a/src/utils/api.test.ts b/src/utils/api.test.ts index f110ff0f8..87e0806e6 100644 --- a/src/utils/api.test.ts +++ b/src/utils/api.test.ts @@ -3,22 +3,12 @@ import { handleResponseType } from '../../src/utils/api'; describe('api', () => { - // no the best mock, but I'd look for a mock library to work with fetch in the future - // @ts-ignore - const headers: Headers = { - // @ts-ignore - get: () => [], - }; - describe('handleResponseType', () => { test('should handle missing Content-Type', async () => { const response: Response = { url: 'http://localhost:8080/-/packages', ok: false, - // @ts-ignore - headers: { - get: () => null, - } as Headers, + headers: new Headers(), } as Response; const handled = await handleResponseType(response); @@ -34,7 +24,7 @@ describe('api', () => { url: 'http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz', blob: () => blobPromise, ok: true, - headers, + headers: new Headers(), } as Response; const handled = await handleResponseType(response); diff --git a/src/utils/api.ts b/src/utils/api.ts index 61bfd4cc6..f0a5e3644 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -6,7 +6,7 @@ import '../../types'; * @param {object} response * @returns {promise} */ -export function handleResponseType(response: Response): Promise<[boolean, Blob | string]> | Promise { +export function handleResponseType(response: Response): Promise<[boolean, Blob | string] | void> { if (response.headers) { const contentType = response.headers.get('Content-Type'); if (contentType && contentType.includes('application/pdf')) { @@ -52,7 +52,6 @@ class API { credentials: 'same-origin', ...options, }) - // @ts-ignore .then(handleResponseType) .then(response => { if (response[0]) { diff --git a/src/utils/calls.ts b/src/utils/calls.ts index 2ae6488e3..1aaada674 100644 --- a/src/utils/calls.ts +++ b/src/utils/calls.ts @@ -12,7 +12,7 @@ export async function callDetailPage(packageName: string, packageVersion?: strin return packageMeta; } -export function callSearch(value: string, signal: any) { +export function callSearch(value: string, signal: AbortSignal) { // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#Browser_compatibility // FUTURE: signal is not well supported for IE and Samsung Browser return API.request(`search/${encodeURIComponent(value)}`, 'GET', { signal, headers: {} });