Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Type promises #47

Merged
merged 1 commit into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function callApiAndParseWithTimeout({

const racedPromise =
typeof timeout === 'number' && timeout > 0
? Promise.race([rejectAfterTimeout(timeout), apiPromise])
? Promise.race([rejectAfterTimeout<Response>(timeout), apiPromise])
: apiPromise;

return parseResponse(racedPromise, parseMethod);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// returns a Promise that rejects after the specified timeout
export default function rejectAfterTimeout(timeout: number): Promise<any> {
export default function rejectAfterTimeout<T>(timeout: number): Promise<T> {
return new Promise((resolve, reject) => {
setTimeout(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as rejectAfterTimeout from '../../src/callApi/rejectAfterTimeout';

import { LOGIN_GLOB } from '../fixtures/constants';
import throwIfCalled from '../utils/throwIfCalled';
import { JsonResponse } from '../../src/types';
import { Json } from '../../src/types';

describe('callApiAndParseWithTimeout()', () => {
beforeAll(() => {
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('callApiAndParseWithTimeout()', () => {
jest.useFakeTimers();

return callApiAndParseWithTimeout({ url: mockGetUrl, method: 'GET', timeout: 100 }).then(
(response: JsonResponse) => {
(response: Json) => {
expect(response.json).toEqual(expect.objectContaining(mockGetPayload));

return Promise.resolve();
Expand Down