diff --git a/index.d.ts b/index.d.ts index 0d60588..b483327 100644 --- a/index.d.ts +++ b/index.d.ts @@ -20,13 +20,13 @@ declare namespace LightMyRequest { callback: CallbackFunc ): void - type DispatchFunc = (req: Request, res: Response) => void + type DispatchFunc = (req: Request, res: ServerResponse) => void type CallbackFunc = (err: Error, response: Response) => void type InjectPayload = string | object | Buffer | NodeJS.ReadableStream - function isInjection (obj: Request | Response): boolean + function isInjection (obj: Request | ServerResponse): boolean interface InjectOptions { url?: string | { @@ -71,7 +71,9 @@ declare namespace LightMyRequest { connection: object } - interface Response extends http.ServerResponse { + interface ServerResponse extends http.ServerResponse {} + + interface Response { raw: { res: http.ServerResponse, req: Request diff --git a/test/index.test-d.ts b/test/index.test-d.ts index e6bf994..74a3b41 100644 --- a/test/index.test-d.ts +++ b/test/index.test-d.ts @@ -1,10 +1,10 @@ import * as http from 'http' -import { inject, isInjection, Request, Response, DispatchFunc, InjectOptions, Chain } from '../index' -import { expectType, expectAssignable } from 'tsd' +import { inject, isInjection, Request, Response, DispatchFunc, InjectOptions, Chain, ServerResponse } from '../index' +import { expectType, expectAssignable, expectNotAssignable } from 'tsd' expectAssignable({ url: '/' }) -const dispatch = function (req: Request, res: Response) { +const dispatch = function (req: Request, res: ServerResponse) { expectType(isInjection(req)) expectType(isInjection(res)) @@ -17,7 +17,7 @@ const expectResponse = function (res: Response) { expectType(res) console.log(res.payload) expectAssignable(res.json) - expectAssignable(res.raw.res) + expectAssignable(res.raw.res) expectAssignable(res.raw.req) console.log(res.cookies) } @@ -88,3 +88,5 @@ expectType(parsedValue) const parsedValueUsingGeneric = response.json() expectType(parsedValueUsingGeneric) + +expectNotAssignable(response)