Skip to content

Commit 2de60d4

Browse files
Merge pull request DefinitelyTyped#19476 from BendingBender/http-error-never
[http-errors] don't return never from HttpError constructor
2 parents 60a9997 + 68b6849 commit 2de60d4

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

types/http-errors/http-errors-tests.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ err = create(404, 'LOL', {id: 1});
7171
// create(status, msg, { expose: false })
7272
err = create(404, 'LOL', {expose: false});
7373

74-
// new create.HttpError() should throw: cannot construct abstract class
75-
// $ExpectType never
76-
new create.HttpError();
77-
7874
err = new create.NotFound();
7975
err = new create.InternalServerError();
8076
err = new create[404]();
@@ -91,9 +87,16 @@ err = new create[404]('This might be a problem');
9187
err = new create.MisdirectedRequest();
9288
err = new create.MisdirectedRequest('Where should this go?');
9389

90+
// $ExpectType HttpError
91+
new create.HttpError();
92+
9493
// $ExpectType boolean
9594
new Error() instanceof create.HttpError;
9695

96+
if (err instanceof create.HttpError) {
97+
err.statusCode;
98+
}
99+
97100
// should support err instanceof Error
98101
create(404) instanceof Error;
99102
(new create['404']()) instanceof Error;

types/http-errors/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Definitions by: Tanguy Krotoff <https://github.com/tkrotoff>
44
// BendingBender <https://github.com/BendingBender>
55
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6-
// TypeScript Version: 2.3
6+
// TypeScript Version: 2.2
77

88
export = createHttpError;
99

@@ -26,7 +26,7 @@ declare namespace createHttpError {
2626

2727
type NamedConstructors = {
2828
[code: string]: HttpErrorConstructor;
29-
HttpError: new (msg?: string) => never;
29+
HttpError: HttpErrorConstructor;
3030
} & Record<'BadRequest' |
3131
'Unauthorized' |
3232
'PaymentRequired' |

0 commit comments

Comments
 (0)