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

fix(types): improve TypeScript strict typing for numeric keys in HttpStatus #49

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ declare const httpStatus: httpStatus.HttpStatus;

declare namespace httpStatus {
interface HttpStatus {
readonly [key: number]: string | undefined;

readonly [key: string]:
| string
| number
| HttpStatusClasses
| HttpStatusExtra
| undefined;

readonly 100: string;
readonly '100_NAME': string;
readonly '100_MESSAGE': string;
Expand Down Expand Up @@ -395,8 +386,6 @@ declare namespace httpStatus {
}

interface HttpStatusClasses {
readonly [key: string]: string | number;

readonly '1xx': string;
readonly '1xx_NAME': string;
readonly '1xx_MESSAGE': string;
Expand Down Expand Up @@ -424,8 +413,6 @@ declare namespace httpStatus {
}

interface HttpStatusUnofficial {
readonly [key: string]: string | number;

readonly 103: string;
readonly '103_NAME': string;
readonly '103_MESSAGE': string;
Expand Down Expand Up @@ -476,8 +463,6 @@ declare namespace httpStatus {
}

interface HttpStatusIis {
readonly [key: string]: string | number;

readonly 440: string;
readonly '440_NAME': string;
readonly '440_MESSAGE': string;
Expand All @@ -498,8 +483,6 @@ declare namespace httpStatus {
}

interface HttpStatusNginx {
readonly [key: string]: string | number;

readonly 444: string;
readonly '444_NAME': string;
readonly '444_MESSAGE': string;
Expand Down
17 changes: 0 additions & 17 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ declare const httpStatus: httpStatus.HttpStatus;

declare namespace httpStatus {
interface HttpStatus {
readonly [key: number]: string | undefined;

readonly [key: string]:
| string
| number
| HttpStatusClasses
| HttpStatusExtra
| undefined;

readonly 100: string;
readonly '100_NAME': string;
readonly '100_MESSAGE': string;
Expand Down Expand Up @@ -395,8 +386,6 @@ declare namespace httpStatus {
}

interface HttpStatusClasses {
readonly [key: string]: string | number;

readonly '1xx': string;
readonly '1xx_NAME': string;
readonly '1xx_MESSAGE': string;
Expand Down Expand Up @@ -424,8 +413,6 @@ declare namespace httpStatus {
}

interface HttpStatusUnofficial {
readonly [key: string]: string | number;

readonly 103: string;
readonly '103_NAME': string;
readonly '103_MESSAGE': string;
Expand Down Expand Up @@ -476,8 +463,6 @@ declare namespace httpStatus {
}

interface HttpStatusIis {
readonly [key: string]: string | number;

readonly 440: string;
readonly '440_NAME': string;
readonly '440_MESSAGE': string;
Expand All @@ -498,8 +483,6 @@ declare namespace httpStatus {
}

interface HttpStatusNginx {
readonly [key: string]: string | number;

readonly 444: string;
readonly '444_NAME': string;
readonly '444_MESSAGE': string;
Expand Down
4 changes: 2 additions & 2 deletions test/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ describe('Types', () => {

it('undefined status codes', () => {
const undefinedStatusCode = 777
const code: string = typeof status[undefinedStatusCode]
const code: string = typeof (status as any)[undefinedStatusCode]
code.should.eql('undefined')
})

it('sub level properties', () => {
const number: number = status.extra.nginx.NO_RESPONSE
const number: 444 = status.extra.nginx.NO_RESPONSE
const code: string = status.extra.nginx[number] as string
code.should.eql('No Response')
const name: string = status.extra.nginx[`${number}_NAME`] as string
Expand Down
Loading