wondering how to define the type of body of an API POST Nextjs route in order to benefit from typesafety ? In the NextApiRequest, body is defined as "any" and NextApiRequest is not generic
using as force the type but this is not clean at all
running NextJs12 and typescript 4.4.4
import { NextApiRequest, NextApiResponse } from "next";
interface IBody {
test: string;
value: number;
}
const handler = async (
req: NextApiRequest, <-- whish to have something here like NextApiRequest<TQuery, TBody,..>
res: NextApiResponse
): Promise<void> => {
const { body } = req;
console.log(body as IBody); <--this is not safe at all
res.status(200).json({ text: "Hello" });
};
export default handler;