[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:
Niklas Wulf
2018-01-17 18:57:36 +01:00
committed by Wesley Wigham
parent 2c7e6c4f09
commit 6faad9d199
2 changed files with 7 additions and 1 deletions

View File

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

View File

@@ -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
/**