Skip to content

Commit 82523b8

Browse files
authored
fix: use unknown type for middleware result (#95)
1 parent b120a63 commit 82523b8

File tree

4 files changed

+6
-11
lines changed

4 files changed

+6
-11
lines changed

src/types.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ export interface AppRouteHandler {
149149
(
150150
req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>,
151151
res: Response<any, Record<string, any>>,
152-
): void | Promise<void>;
152+
): unknown;
153153
}
154154
/* eslint-enable @typescript-eslint/no-explicit-any */
155155

156156
export interface AppMiddleware {
157-
(req: Request, res: Response, next: NextFunction): void | Promise<void>;
157+
(req: Request, res: Response, next: NextFunction): unknown;
158158
}
159159

160160
export interface AppAuthHandler extends AppMiddleware {}
@@ -164,12 +164,7 @@ export interface ExpressFinalError extends Error {
164164
}
165165

166166
export interface AppErrorHandler {
167-
(
168-
error: ExpressFinalError,
169-
req: Request,
170-
res: Response,
171-
next: NextFunction,
172-
): void | Promise<void>;
167+
(error: ExpressFinalError, req: Request, res: Response, next: NextFunction): unknown;
173168
}
174169

175170
export interface SetupParams {

src/validator/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ interface TypedResponseMethods<TContent extends Record<number, z.ZodType | {sche
7474
data?: ExtractSchemaFromResponseDef<TContent[S]> extends never
7575
? undefined
7676
: InferDataFromResponseDef<TContent[S]>, // Exact not always needed for serialize, but good for consistency
77-
) => void;
77+
) => Promise<void>;
7878
}
7979

8080
export interface RouteContract {

src/validator/with-contract.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function withContract<
4949
Params['THeaders']
5050
>,
5151
res: ContractResponse<TConfig>,
52-
) => Promise<void> | void,
52+
) => unknown,
5353
) {
5454
const finalHandler: AppRouteHandler = async (
5555
expressReq: ExpressRequest,

src/validator/with-error-contract.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function withErrorContract<TConfig extends ErrorContract>(config: TConfig
1010
req: ExpressRequest,
1111
res: ErrorResponse<TConfig>,
1212
next: (err?: Error) => void,
13-
) => Promise<void> | void,
13+
) => unknown,
1414
) {
1515
const finalHandler: AppErrorHandler = (
1616
err: Error,

0 commit comments

Comments
 (0)