From 68b6849bf5dd4bcc64eebe98c85533992f31a12f Mon Sep 17 00:00:00 2001 From: user Date: Thu, 31 Aug 2017 10:39:10 +0200 Subject: [PATCH] [http-errors] don't return never from HttpError constructor --- types/http-errors/http-errors-tests.ts | 11 +++++++---- types/http-errors/index.d.ts | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/types/http-errors/http-errors-tests.ts b/types/http-errors/http-errors-tests.ts index c90c360610..c3677fd5f9 100644 --- a/types/http-errors/http-errors-tests.ts +++ b/types/http-errors/http-errors-tests.ts @@ -71,10 +71,6 @@ err = create(404, 'LOL', {id: 1}); // create(status, msg, { expose: false }) err = create(404, 'LOL', {expose: false}); -// new create.HttpError() should throw: cannot construct abstract class -// $ExpectType never -new create.HttpError(); - err = new create.NotFound(); err = new create.InternalServerError(); err = new create[404](); @@ -91,9 +87,16 @@ err = new create[404]('This might be a problem'); err = new create.MisdirectedRequest(); err = new create.MisdirectedRequest('Where should this go?'); +// $ExpectType HttpError +new create.HttpError(); + // $ExpectType boolean new Error() instanceof create.HttpError; +if (err instanceof create.HttpError) { + err.statusCode; +} + // should support err instanceof Error create(404) instanceof Error; (new create['404']()) instanceof Error; diff --git a/types/http-errors/index.d.ts b/types/http-errors/index.d.ts index 5db6e497e7..376c140d90 100644 --- a/types/http-errors/index.d.ts +++ b/types/http-errors/index.d.ts @@ -3,7 +3,7 @@ // Definitions by: Tanguy Krotoff // BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.2 export = createHttpError; @@ -26,7 +26,7 @@ declare namespace createHttpError { type NamedConstructors = { [code: string]: HttpErrorConstructor; - HttpError: new (msg?: string) => never; + HttpError: HttpErrorConstructor; } & Record<'BadRequest' | 'Unauthorized' | 'PaymentRequired' |