-
Notifications
You must be signed in to change notification settings - Fork 55
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
Unable to properly infer numeric keys in TypeScript type with mixed key types #48
Comments
Is there a reason for the |
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. |
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! |
…Status (#49) The TypeScript type inference for numeric keys in the HttpStatus interface was previously unspecific, causing issues in strict typing scenarios. This fix removes unnecessary declarations, ensuring more accurate and strict TypeScript typing for numeric keys. It also includes updates to unit tests to reflect and validate the improved strict typing. Closes #48
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
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.The text was updated successfully, but these errors were encountered: