'An argument for 'body' was not provided for send() \ json() in Next.js's API, with TypeScript

I'm using an API route in Next.js. In the 'api' folder, my 'file.tsx' contain the following:

import type { NextApiRequest, NextApiResponse } from "next";
const someFunction = (req: NextApiRequest, res: NextApiResponse<data>) => { the rest of the code... }

Everything does work. But, regarding the following line:

res.status(200).send();

send() is highlighted and I get the following TypeScript error:

Expected 1 arguments, but got 0.ts(2554) utils.d.ts(182, 25): An argument for 'body' was not provided.

Following the docs (https://nextjs.org/docs/api-routes/response-helpers), I tried adding an argument like res.status(200).send({key: "value"}), or res.status(200).send("string") or both with json() instead of send().

I even copied the exact examples from the docs, but still this error persist. The only thing that cleared the error (as a test) was changing the typing - but naturally, this is undesirable, as the error is probably there for a reason.

Am I missing something here?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source