this is a simple api route i have:
// import prisma from "../../../utils/db";
import {NextRequest, NextResponse} from "next/server";
const addresses = [
{
id: 1,
name: "John Doe",
email: "[email protected]",
phone: "0123456789",
address: "123 Main Street, Anytown, USA",
city: "Anytown",
state: "USA",
zip: "12345",
country: "USA"
},
{
id: 2,
name: "John Doe",
email: "[email protected]",
phone: "0123456789",
address: "123 Main Street, Anytown, USA",
city: "Anytown",
state: "USA",
zip: "12345",
country: "USA"
}
];
export async function GET(request: NextRequest) {
return NextResponse.json(addresses, {status: 200});
}
the problem is that {status: 200} never compile when its used with NextResponse.json(….), it works fine with Response.json(….).
i read about some exemples in the Documentation, they use status:200 with the NextResponse.json!
i read the documentation, they use:
import { NextResponse } from 'next/server'
export async function GET(request: Request) {
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 })
}
i copied the same bloque of code in my IntellJ IDEA, and agains the ‘{ status: 500 }’ dosn’t compile, always gives this error:
“Argument type {status: number} is not assignable to parameter type ResponseInit | undefined”
it works only if i use Response.json instead of NextResponse.json
Just Relax قناة هدوء is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.