From ec0977d8d5f20dd2a41c859cdbf5f4c0c4e12337 Mon Sep 17 00:00:00 2001 From: Igor Stepanov Date: Sat, 24 Nov 2018 15:24:34 +0300 Subject: [PATCH] @types/got: add TimeoutError interface Add `got.TimeoutError` in accordance with sindresorhus/got@da4f23699dead63f17b5e27f9cadd9e4cb95e9a9 --- types/got/got-tests.ts | 1 + types/got/index.d.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/types/got/got-tests.ts b/types/got/got-tests.ts index 934adfc9a8..55680e7d27 100644 --- a/types/got/got-tests.ts +++ b/types/got/got-tests.ts @@ -269,3 +269,4 @@ got('http://todomvc.com', { retry: 2 }); got('http://todomvc.com', { retry: { retries: 2, methods: ['GET'], statusCodes: [408, 504], maxRetryAfter: 1 } }); got('http://todomvc.com', { throwHttpErrors: false }); got('http://todomvc.com', { hooks: { beforeRequest: [ () => 'foo']} }); +got('http://todomvc.com', { timeout: 1 }).catch((e) => e instanceof got.TimeoutError); diff --git a/types/got/index.d.ts b/types/got/index.d.ts index 6b0929fdcf..d0cfc682dc 100644 --- a/types/got/index.d.ts +++ b/types/got/index.d.ts @@ -53,6 +53,10 @@ declare class CancelError extends StdError { name: 'CancelError'; } +declare class TimeoutError extends StdError { + name: 'TimeoutError'; +} + declare class StdError extends Error { code?: string; host?: string; @@ -75,6 +79,7 @@ declare const got: got.GotFn & MaxRedirectsError: typeof MaxRedirectsError; UnsupportedProtocolError: typeof UnsupportedProtocolError; CancelError: typeof CancelError; + TimeoutError: typeof TimeoutError; }; interface InternalRequestOptions extends https.RequestOptions { @@ -215,7 +220,7 @@ declare namespace got { removeListener(event: 'uploadProgress', listener: (progress: Progress) => void): this; } - type GotError = RequestError | ReadError | ParseError | HTTPError | MaxRedirectsError | UnsupportedProtocolError | CancelError; + type GotError = RequestError | ReadError | ParseError | HTTPError | MaxRedirectsError | UnsupportedProtocolError | CancelError | TimeoutError; interface Progress { percent: number;