mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 19:09:18 +08:00
[boom] isBoom is a type-guard (#22918)
Instead of just returning boolean, the `isBoom` function can and should be a type-guard, which enables the obvious benefits.
This commit is contained in:
committed by
Wesley Wigham
parent
2c7e6c4f09
commit
6faad9d199
@@ -144,6 +144,12 @@ const isBoomError = new Boom.Boom('test')
|
||||
|
||||
Boom.isBoom(isBoomError);
|
||||
|
||||
const maybeBoom = <any>new Boom.Boom('test');
|
||||
if(Boom.isBoom(maybeBoom)) {
|
||||
// isBoom is a type guard that allows accessing these properties:
|
||||
maybeBoom.output.headers;
|
||||
}
|
||||
|
||||
// constructor
|
||||
|
||||
const constructorError: Boom.Boom = new Boom.Boom('test');
|
||||
|
||||
2
types/boom/index.d.ts
vendored
2
types/boom/index.d.ts
vendored
@@ -86,7 +86,7 @@ declare namespace Boom {
|
||||
* Identifies whether an error is a Boom object. Same as calling instanceof Boom.
|
||||
* @param error the error object to identify.
|
||||
*/
|
||||
export function isBoom(error: Error): boolean
|
||||
export function isBoom(error: Error): error is Boom
|
||||
|
||||
// 4xx
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user