Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.

Commit 5d6ad3d

Browse files
tmknjuanpicado
authored andcommitted
fix: api typings (#210)
1 parent 5c06ace commit 5d6ad3d

File tree

4 files changed

+4
-16
lines changed

4 files changed

+4
-16
lines changed

src/components/Search/Search.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ export class Search extends Component<RouteComponentProps<{}>, State> {
139139
*/
140140
private handleFetchPackages: handleFetchPackages = async ({ value }) => {
141141
try {
142-
// @ts-ignore
143142
const controller = new window.AbortController();
144143
const signal = controller.signal;
145144
// Keep track of search requests.

src/utils/api.test.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,12 @@
33
import { handleResponseType } from '../../src/utils/api';
44

55
describe('api', () => {
6-
// no the best mock, but I'd look for a mock library to work with fetch in the future
7-
// @ts-ignore
8-
const headers: Headers = {
9-
// @ts-ignore
10-
get: () => [],
11-
};
12-
136
describe('handleResponseType', () => {
147
test('should handle missing Content-Type', async () => {
158
const response: Response = {
169
url: 'http://localhost:8080/-/packages',
1710
ok: false,
18-
// @ts-ignore
19-
headers: {
20-
get: () => null,
21-
} as Headers,
11+
headers: new Headers(),
2212
} as Response;
2313

2414
const handled = await handleResponseType(response);
@@ -34,7 +24,7 @@ describe('api', () => {
3424
url: 'http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz',
3525
blob: () => blobPromise,
3626
ok: true,
37-
headers,
27+
headers: new Headers(),
3828
} as Response;
3929
const handled = await handleResponseType(response);
4030

src/utils/api.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import '../../types';
66
* @param {object} response
77
* @returns {promise}
88
*/
9-
export function handleResponseType(response: Response): Promise<[boolean, Blob | string]> | Promise<void> {
9+
export function handleResponseType(response: Response): Promise<[boolean, Blob | string] | void> {
1010
if (response.headers) {
1111
const contentType = response.headers.get('Content-Type');
1212
if (contentType && contentType.includes('application/pdf')) {
@@ -52,7 +52,6 @@ class API {
5252
credentials: 'same-origin',
5353
...options,
5454
})
55-
// @ts-ignore
5655
.then(handleResponseType)
5756
.then(response => {
5857
if (response[0]) {

src/utils/calls.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export async function callDetailPage(packageName: string, packageVersion?: strin
1212
return packageMeta;
1313
}
1414

15-
export function callSearch(value: string, signal: any) {
15+
export function callSearch(value: string, signal: AbortSignal) {
1616
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#Browser_compatibility
1717
// FUTURE: signal is not well supported for IE and Samsung Browser
1818
return API.request(`search/${encodeURIComponent(value)}`, 'GET', { signal, headers: {} });

0 commit comments

Comments
 (0)