I am facing an issue with typescript while trying to use my own custom type from express' types.
When I attempt to pass 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' as a parameter of type 'Context', I get an error saying it is not assignable.
The error mentioned that the property 'req' is missing in type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>', but it's required in type 'Context'.
Although the type signatures seem identical, I'm struggling to figure out what mistake I'm making here.
How can I successfully pass req
and res
to the function getStatus
?
Routes.ts
import getStatus from "../routes/status";
export default function routes({ app }: Context): void {
app.get("/_status", ({ req, res }: Context) => getStatus(req, res));
} // digging into issues here ^^^^^^^^
Status.ts
import { Context } from "../../utils/Context";
import express from "express";
export default async function getStatus({req}: Context, { res }: Context): Promise<Express.Response> {
//....
}
Context.ts
import { Request, Response, Application } from "express";
export type Context = {
req: Request;
res: Response;
app: Application;
};