From 405e96b33ec220e5e75267087891f352c578a9a9 Mon Sep 17 00:00:00 2001 From: Gil Pedersen Date: Wed, 27 May 2026 13:59:00 +0200 Subject: [PATCH] Use type predicate to narrow req --- lib/index.d.ts | 1 + test/index.ts | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/index.d.ts b/lib/index.d.ts index 235c471..f22770b 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -183,4 +183,5 @@ export function inject(dispatchFunc: MaybeInjectionListener, options: RequestOpt * * @return true if the object is a shot request, otherwise false. */ +export function isInjection(obj: MaybeInjectedRequest): obj is InjectedRequest; export function isInjection(obj: MaybeInjectedRequest | ServerResponse): boolean; diff --git a/test/index.ts b/test/index.ts index 9b29f6a..dc0d84c 100644 --- a/test/index.ts +++ b/test/index.ts @@ -60,6 +60,13 @@ await Shot.inject((req: Shot.MaybeInjectedRequest, res) => { expect.type(Shot.isInjection(req)); expect.type(Shot.isInjection(res)); + if (Shot.isInjection(req)) { + expect.type(req); + } + else { + expect.type(req); + } + res.end(); }, '/');