Description
This is my indexWithZod.ts file:
import { z } from 'zod';
export const appWithZod = express();
appWithZod.use(express.json());
const sumInput = z.object({
a: z.number(),
b: z.number()
});
appWithZod.post('/sum', (req, res) => {
const parsedResponse = sumInput.safeParse(req.body);
if (!parsedResponse.success) {
return res.status(411).json({
message: 'Incorrect inputs'
});
}
const answer = parsedResponse.data.a + parsedResponse.data.b;
return res.json({
answer
});
});
I am getting error at (req, res) => {
where the exact error message is
No overload matches this call.
The last overload gave the following error.
Argument of type '(req: Request<{}, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>) => Response<any, Record<...>, number>' is not assignable to parameter of type 'Application<Record<string, any>>'.
Type '(req: Request<{}, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>) => Response<any, Record<...>, number>' is missing the following properties from type 'Application<Record<string, any>>': init, defaultConfiguration, engine, set, and 63 more.ts(2769)
Here is the additional bin.ts file for reference:
import { appWithZod } from './indexWithZod';
appWithZod.listen(3001, () => {
console.log('Server (appWithZod) is running on PORT 3001');
});