-
Notifications
You must be signed in to change notification settings - Fork 58
Closed
Description
The library returns undefined for unknown status codes, which is not reflected in the types.
import * as HttpStatus from 'http-status';
const ok = HttpStatus[200];
const thisIsUndefinedAndNotAString = HttpStatus[777];
console.log(typeof ok); // prints string
console.log(ok); // prints ok
console.log(typeof thisIsUndefinedAndNotAString); // this prints undefined
console.log(thisIsUndefinedAndNotAString); // this prints undefined
So I guess this would be a rather correct type:
declare namespace httpStatus {
interface HttpStatus {
readonly [key: number]: string | undefined
readonly [key: string]:
| string
| number
| HttpStatusClasses
| HttpStatusExtra
| undefined;
For convenience - as the lib might quite often be used to trace foreign messages, where you might not rely on correct content - the types might even be extended (last lines to give concrete values priority) with:
readonly [key: undefined]: undefined
or
readonly [key: unknown]: undefined
But these are really optional and opinionated.
I might provide a PR with the fix and/or the feature, if it is accepted
Metadata
Metadata
Assignees
Labels
No labels