Skip to content

Commit

Permalink
fix(types): add undefined to types
Browse files Browse the repository at this point in the history
close #43
  • Loading branch information
Retro64 authored Jan 10, 2023
1 parent 08923fd commit 8efa2e1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
11 changes: 6 additions & 5 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ declare const httpStatus: httpStatus.HttpStatus;

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

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

readonly 100: string;
readonly '100_NAME': string;
Expand Down
11 changes: 6 additions & 5 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ declare const httpStatus: httpStatus.HttpStatus;

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

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

readonly 100: string;
readonly '100_NAME': string;
Expand Down
26 changes: 16 additions & 10 deletions test/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ describe('Types', () => {
const clazz: string = status[`${number}_CLASS`] as string
clazz.should.eql('1xx')
})


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

it('sub level properties', () => {
const number: number = status.extra.nginx.NO_RESPONSE
const code: string = status.extra.nginx[number] as string
Expand All @@ -38,41 +44,41 @@ describe('Types', () => {
const clazz: string = status.extra.nginx[`${number}_CLASS`] as string
clazz.should.eql('4xx')
})

})

describe('ES6 exports', () => {

it('HttpStatus', () => {
const statuses: HttpStatus = status
statuses.CONTINUE.should.be.a.Number()
})

it('HttpStatusClasses', () => {
const classes: HttpStatusClasses = status.classes
classes.INFORMATIONAL.should.be.a.String()
})

it('HttpStatusUnofficial', () => {
const unofficial: HttpStatusUnofficial = status.extra.unofficial
unofficial.CHECKPOINT.should.be.a.Number()
})

it('HttpStatusIis', () => {
const iis: HttpStatusIis = status.extra.iis
iis.LOGIN_TIME_OUT.should.be.a.Number()
})

it('HttpStatusNginx', () => {
const nginx: HttpStatusNginx = status.extra.nginx
nginx.NO_RESPONSE.should.be.a.Number()
})

it('HttpStatusCloudfare', () => {
const cloudflare: HttpStatusCloudfare = status.extra.cloudflare
cloudflare.UNKNOWN_ERROR.should.be.a.Number()
})

})

})

0 comments on commit 8efa2e1

Please sign in to comment.