Skip to content

Commit e64ba29

Browse files
authored
Add missing type for Response.raw.req (#92)
* Add missing type for Response.raw.req It's added here: https://github.com/fastify/light-my-request/blob/master/lib/response.js#L40 * add tests for raw response property types
1 parent 634baa9 commit e64ba29

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ declare namespace LightMyRequest {
7070

7171
interface Response extends http.ServerResponse {
7272
raw: {
73-
res: http.ServerResponse
73+
res: http.ServerResponse,
74+
req: Request
7475
}
7576
rawPayload: Buffer
7677
headers: http.OutgoingHttpHeaders

test/index.test-d.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as http from 'http'
12
import { inject, isInjection, Request, Response, DispatchFunc, InjectOptions, Chain } from '../index'
23
import { expectType, expectAssignable } from 'tsd'
34

@@ -12,14 +13,20 @@ const dispatch = function (req: Request, res: Response) {
1213
res.end(reply)
1314
}
1415

15-
expectType<DispatchFunc>(dispatch)
16-
17-
inject(dispatch, { method: 'get', url: '/' }, (err, res) => {
18-
expectType<Error>(err)
16+
const expectResponse = function (res: Response) {
1917
expectType<Response>(res)
2018
console.log(res.payload)
2119
expectAssignable<Function>(res.json)
20+
expectAssignable<http.ServerResponse>(res.raw.res)
21+
expectAssignable<Request>(res.raw.req)
2222
console.log(res.cookies)
23+
}
24+
25+
expectType<DispatchFunc>(dispatch)
26+
27+
inject(dispatch, { method: 'get', url: '/' }, (err, res) => {
28+
expectType<Error>(err)
29+
expectResponse(res)
2330
})
2431

2532
const url = {
@@ -33,34 +40,22 @@ const url = {
3340
}
3441
inject(dispatch, { method: 'get', url }, (err, res) => {
3542
expectType<Error>(err)
36-
expectType<Response>(res)
37-
console.log(res.payload)
38-
expectAssignable<Function>(res.json)
39-
console.log(res.cookies)
43+
expectResponse(res)
4044
})
4145

4246
inject(dispatch, { method: 'get', url: '/', cookies: { name1: 'value1', value2: 'value2' } }, (err, res) => {
4347
expectType<Error>(err)
44-
expectType<Response>(res)
45-
console.log(res.payload)
46-
expectAssignable<Function>(res.json)
47-
console.log(res.cookies)
48+
expectResponse(res)
4849
})
4950

5051
inject(dispatch, { method: 'get', url: '/', query: { name1: 'value1', value2: 'value2' } }, (err, res) => {
5152
expectType<Error>(err)
52-
expectType<Response>(res)
53-
console.log(res.payload)
54-
expectAssignable<Function>(res.json)
55-
console.log(res.cookies)
53+
expectResponse(res)
5654
})
5755

5856
inject(dispatch, { method: 'get', url: '/', query: { name1: ['value1', 'value2'] } }, (err, res) => {
5957
expectType<Error>(err)
60-
expectType<Response>(res)
61-
console.log(res.payload)
62-
expectAssignable<Function>(res.json)
63-
console.log(res.cookies)
58+
expectResponse(res)
6459
})
6560

6661
inject(dispatch)

0 commit comments

Comments
 (0)