Closed aronmal closed 6 months ago
Is there a reason for the readonly [key: number]
? If not I can create a pull request, but I wanted to ask first if it has an origin.
I don't think so, or I don't have a memory for it. Please propose your change if you feel confident. I personally don't use TS.
Also, add a unit test to support your claim.
Also, add a unit test to support your claim.
I've addressed the comment about adding a unit test. While there isn't a specific test to showcase the issue due to the nature of the problem (lack of strictness in types allowing more keys than intended), I did enhance the existing unit tests because during this process, a type error in the test file surfaced. But it has been taken care of.
If you have any further suggestions, let me know!
Describe the bug
When utilizing the
http-status
package, there is a bug related to inferring numeric keys in TypeScript when working with a mixed type declaration within theHttpStatus
interface in index.d.ts.To Reproduce
To reproduce the issue, consider the following TypeScript code snippet:
In this case, the types do not work correctly and autocompletion does show any possible string in the ide![image](https://github.com/adaltas/node-http-status/assets/57275207/e77d7d01-6de1-4929-aa21-bf3e9e7b30bc)
When changing the type input to the example object:
it then works and shows the correct types
Additionally, the unnecessary declaration
readonly [key: number]: string | undefined;
in theHttpStatus
interface contributes to the issue and might be impacting TypeScript type inference.Additional context
The issue seems to be associated with the mixed type declaration within the
HttpStatus
interface in index.d.ts, specifically:This declaration allows for both string and number keys, leading to unexpected behavior in TypeScript type inference. The bug impacts TypeScript type inference in projects utilizing the
http-status
package, particularly when trying to enforce strict typing for numeric keys. The unnecessaryreadonly [key: number]
declaration are causing the issue and should be considered for removal.