From c5687bab45134d7ee69df6cbcd9459d3bf215002 Mon Sep 17 00:00:00 2001 From: Alexandru Savin Date: Fri, 22 Nov 2019 16:46:28 +0100 Subject: [PATCH] [@types/node-fetch] Fix FetchError class definition (#40581) * Fix FetchError class definition * Add myself to "Definitions by" section of package header --- types/node-fetch/index.d.ts | 7 ++++++- types/node-fetch/node-fetch-tests.ts | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/types/node-fetch/index.d.ts b/types/node-fetch/index.d.ts index 311b1496f4..5756c6566c 100644 --- a/types/node-fetch/index.d.ts +++ b/types/node-fetch/index.d.ts @@ -9,6 +9,7 @@ // Brandon Wilson // Steve Faulkner // ExE Boss +// Alex Savin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -148,9 +149,13 @@ export class Body { timeout: number; } +interface SystemError extends Error { + code?: string; +} + export class FetchError extends Error { name: "FetchError"; - constructor(message: string, type: string, systemError?: string); + constructor(message: string, type: string, systemError?: SystemError); type: string; code?: string; errno?: string; diff --git a/types/node-fetch/node-fetch-tests.ts b/types/node-fetch/node-fetch-tests.ts index 6f51f2a8b7..1d1ef8317d 100644 --- a/types/node-fetch/node-fetch-tests.ts +++ b/types/node-fetch/node-fetch-tests.ts @@ -158,7 +158,15 @@ function test_isRedirect() { } function test_FetchError() { - new FetchError("message", "type", "systemError"); + new FetchError("message", "type", { + name: 'Error', + message: 'Error message', + code: "systemError", + }); + new FetchError("message", "type", { + name: 'Error', + message: "Error without code", + }); new FetchError("message", "type"); }