Skip to content

Commit

Permalink
Type promises (apache#47)
Browse files Browse the repository at this point in the history
- type rejectAfterTimeout with generics.
- fixing an import typo in tests.
  • Loading branch information
xtinec committed Dec 3, 2018
1 parent 96a6487 commit 990a463
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
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

0 comments on commit 990a463

Please sign in to comment.