Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Boom.notFound etc error argument type support #290

Closed
bilalabbad opened this issue Oct 19, 2021 · 1 comment · Fixed by #297 · May be fixed by doron2402/boom#3
Closed

Missing Boom.notFound etc error argument type support #290

bilalabbad opened this issue Oct 19, 2021 · 1 comment · Fixed by #297 · May be fixed by doron2402/boom#3
Labels
bug Bug or defect types TypeScript type definitions

Comments

@bilalabbad
Copy link

bilalabbad commented Oct 19, 2021

Boom function like Boom.notFound etc... works perfectly when Error is passed as 1st argument but is not allowed in index.d.ts

Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): yes

Context

  • node version: 14.18.0
  • module version with issue: 9.1.4
  • last module version without issue: ?
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): Hapi app
  • any other relevant information:

What are you trying to achieve or the steps to reproduce?

When a resource is not found, I throw an NotFoundError then I return a 404.

// 2 ways:
// Normal way
const boomError = Boom.notFound(error.message, error); // Ts checker ok
// secret way
const boomError = Boom.notFound(error); // Ts checker fails but works fine + has better debug details

I decided to use the second way, it works fine but it's not documented. Why?

boom/lib/index.js

Lines 71 to 90 in 88b0a41

constructor(message, options = {}) {
if (message instanceof Error) {
return exports.boomify(Hoek.clone(message), options);
}
const { statusCode = 500, data = null, ctor = exports.Boom } = options;
const error = new Error(message ? message : undefined); // Avoids settings null message
Error.captureStackTrace(error, ctor); // Filter the stack to our external API
error.data = data;
const boom = internals.initialize(error, statusCode);
Object.defineProperty(boom, 'typeof', { value: ctor });
if (options.decorate) {
Object.assign(boom, options.decorate);
}
return boom;
}

What was the result you got?

TS2345: Argument of type 'Error' is not assignable to parameter of type 'string'.

What result did you expect?

No error from Typescript

@bilalabbad bilalabbad added the support Questions, discussions, and general support label Oct 19, 2021
@devinivy devinivy added bug Bug or defect types TypeScript type definitions labels May 1, 2022
@devinivy
Copy link
Member

devinivy commented May 1, 2022

It's true that this is supported, would accept a PR to update the types.

@devinivy devinivy removed the support Questions, discussions, and general support label May 1, 2022
@kanongil kanongil changed the title Boom function like Boom.notFound etc... works perfectly when Error is passed as 1st argument but is not allowed in index.d.ts Missing Boom.notFound etc error argument type support May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or defect types TypeScript type definitions
Projects
None yet
2 participants