Skip to content

Commit

Permalink
Make isBoom type definition laxer
Browse files Browse the repository at this point in the history
Especially useful in hapijs context, where request.response can be a
Boom object. This change allows the TypeScript code to leverage isBoom()
to check if request.response is a Boom object or not, without any noisy typecast.
  • Loading branch information
nulltoken authored and cjihrig committed Nov 30, 2020
1 parent fba8e6e commit b25ee43
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ export interface Output {


/**
* Specifies if an error object is a valid boom object
* Specifies if an object is a valid boom object
*
* @param err - The error object
* @param obj - The object to assess
* @param statusCode - Optional status code
*
* @returns Returns a boolean stating if the error object is a valid boom object and it has the provided statusCode (if present)
*/
export function isBoom(err: Error, statusCode?: number): err is Boom;
export function isBoom(obj: unknown, statusCode?: number): obj is Boom;


/**
Expand Down
6 changes: 3 additions & 3 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ expect.type<boolean>(Boom.boomify(error).isBoom);
expect.type<boolean>(Boom.isBoom(error));
expect.type<boolean>(Boom.isBoom(error, 404));
expect.type<boolean>(Boom.isBoom(Boom.boomify(error)));
expect.type<boolean>(Boom.isBoom('error'));
expect.type<boolean>(Boom.isBoom({ foo: 'bar' }));
expect.type<boolean>(Boom.isBoom({ error: true }));

expect.error(Boom.isBoom(error, 'test'));
expect.error(Boom.isBoom('error'));
expect.error(Boom.isBoom({ foo: 'bar' }));
expect.error(Boom.isBoom({ error: true }));
expect.error(Boom.isBoom());


Expand Down

0 comments on commit b25ee43

Please sign in to comment.