[http-errors] don't return never from HttpError constructor

This commit is contained in:
user 2017-08-31 10:39:10 +02:00
parent 5bb93e3433
commit 68b6849bf5
2 changed files with 9 additions and 6 deletions

View File

@ -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;

View File

@ -3,7 +3,7 @@
// Definitions by: Tanguy Krotoff <https://github.com/tkrotoff>
// BendingBender <https://github.com/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' |