Skip to content

Commit 8efa2e1

Browse files
authored
fix(types): add undefined to types
close #43
1 parent 08923fd commit 8efa2e1

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

lib/index.d.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ declare const httpStatus: httpStatus.HttpStatus;
44

55
declare namespace httpStatus {
66
interface HttpStatus {
7-
readonly [key: number]: string
7+
readonly [key: number]: string | undefined;
88

99
readonly [key: string]:
10-
| string
11-
| number
12-
| HttpStatusClasses
13-
| HttpStatusExtra;
10+
| string
11+
| number
12+
| HttpStatusClasses
13+
| HttpStatusExtra
14+
| undefined;
1415

1516
readonly 100: string;
1617
readonly '100_NAME': string;

src/index.d.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ declare const httpStatus: httpStatus.HttpStatus;
44

55
declare namespace httpStatus {
66
interface HttpStatus {
7-
readonly [key: number]: string
7+
readonly [key: number]: string | undefined;
88

99
readonly [key: string]:
10-
| string
11-
| number
12-
| HttpStatusClasses
13-
| HttpStatusExtra;
10+
| string
11+
| number
12+
| HttpStatusClasses
13+
| HttpStatusExtra
14+
| undefined;
1415

1516
readonly 100: string;
1617
readonly '100_NAME': string;

test/types.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ describe('Types', () => {
2626
const clazz: string = status[`${number}_CLASS`] as string
2727
clazz.should.eql('1xx')
2828
})
29-
29+
30+
it('undefined status codes', () => {
31+
const undefinedStatusCode = 777
32+
const code: string = typeof status[undefinedStatusCode]
33+
code.should.eql('undefined')
34+
})
35+
3036
it('sub level properties', () => {
3137
const number: number = status.extra.nginx.NO_RESPONSE
3238
const code: string = status.extra.nginx[number] as string
@@ -38,41 +44,41 @@ describe('Types', () => {
3844
const clazz: string = status.extra.nginx[`${number}_CLASS`] as string
3945
clazz.should.eql('4xx')
4046
})
41-
47+
4248
})
43-
49+
4450
describe('ES6 exports', () => {
45-
51+
4652
it('HttpStatus', () => {
4753
const statuses: HttpStatus = status
4854
statuses.CONTINUE.should.be.a.Number()
4955
})
50-
56+
5157
it('HttpStatusClasses', () => {
5258
const classes: HttpStatusClasses = status.classes
5359
classes.INFORMATIONAL.should.be.a.String()
5460
})
55-
61+
5662
it('HttpStatusUnofficial', () => {
5763
const unofficial: HttpStatusUnofficial = status.extra.unofficial
5864
unofficial.CHECKPOINT.should.be.a.Number()
5965
})
60-
66+
6167
it('HttpStatusIis', () => {
6268
const iis: HttpStatusIis = status.extra.iis
6369
iis.LOGIN_TIME_OUT.should.be.a.Number()
6470
})
65-
71+
6672
it('HttpStatusNginx', () => {
6773
const nginx: HttpStatusNginx = status.extra.nginx
6874
nginx.NO_RESPONSE.should.be.a.Number()
6975
})
70-
76+
7177
it('HttpStatusCloudfare', () => {
7278
const cloudflare: HttpStatusCloudfare = status.extra.cloudflare
7379
cloudflare.UNKNOWN_ERROR.should.be.a.Number()
7480
})
75-
81+
7682
})
7783

7884
})

0 commit comments

Comments
 (0)