Am I returning CSV file correctly from API route?
Unanswered
Capple posted this in #help-forum
CappleOP
Hello,
I'm wondering if I'm returning the CSV file from my API route correctly.
This works and I can download the file but If I remove the any I get a typescript error
Argument of type 'Stringifier' is not assignable to parameter of type 'BodyInit | null | undefined'.
Type 'Stringifier' is missing the following properties from type 'URLSearchParams': size, append, delete, get, and 8 more.ts(2345)
I'm wondering if I'm returning the CSV file from my API route correctly.
export const GET = auth(async function GET(req) {
const headers = new Headers();
headers.append("Content-Type", "text/csv");
headers.append("Content-Disposition", `attachment; filename="products_${format(new Date(), "yyyy-MM-dd")}.csv"`);
const csvStream = stringify(rows, { header: true, delimiter: ";", bom: true });
return new NextResponse(csvStream as any, { headers });
}
This works and I can download the file but If I remove the any I get a typescript error
Argument of type 'Stringifier' is not assignable to parameter of type 'BodyInit | null | undefined'.
Type 'Stringifier' is missing the following properties from type 'URLSearchParams': size, append, delete, get, and 8 more.ts(2345)