hapijs / boom

HTTP-friendly error objects
Other
2.94k stars 192 forks source link

Missing Boom.notFound etc error argument type support #290

Closed bilalabbad closed 1 year ago

bilalabbad commented 3 years ago

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

Context

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? https://github.com/hapijs/boom/blob/88b0a415856fbe47ee4a90680ebd6a7e502ec60f/lib/index.js#L71-L90

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

devinivy commented 2 years ago

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