Currently, I have set up an API route within Next.js. Within the 'api' directory, my 'file.tsx' consists of the following code:
import type { NextApiRequest, NextApiResponse } from "next";
const someFunction = (req: NextApiRequest, res: NextApiResponse<data>) => { the rest of the code... }
Everything seems to be functioning properly. However, in relation to the line below:
res.status(200).send();
I am encountering a TypeScript error highlighting send()
:
Expected 1 arguments, but got 0.ts(2554) utils.d.ts(182, 25): An argument for 'body' was not provided.
Referring to the documentation (https://nextjs.org/docs/api-routes/response-helpers), I attempted adding an argument such as
res.status(200).send({key: "value"})
, or res.status(200).send("string")
, along with using json()
instead of send()
.
Despite replicating the examples exactly from the documentation, the error persists. Changing the typing temporarily resolved the issue, however, it is likely present for a specific purpose thereby making it an undesirable solution.
Is there something that I may be overlooking here?