Next.js Discord

Discord Forum

HELP Type '(req: Request, res: Response) => Promise<Response>' is not assignable to type 'never'.

Answered
Golden paper wasp posted this in #help-forum
Open in Discord
Golden paper waspOP
using next 14.2.7

been having this errors on my router files.
.next/types/app/api/posts/create/route.ts:8:13
Type error: Type 'OmitWithTag<typeof import("C:/Users/User/Documents/projects/media-platform/src/app/api/posts/create/route"), "GET" | "POST" | "config" | "generateStaticParams" | "revalidate" | "dynamic" | ... 9 more ... | "PATCH", "">' does not satisfy the constraint '{ [x: string]: never; }'.
  Property 'Post' is incompatible with index signature.
    Type '(req: Request, res: Response) => Promise<Response>' is not assignable to type 'never'.

   6 |
   7 | // Check that the entry is a valid entry
>  8 | checkFields<Diff<{
     |             ^
   9 |   GET?: Function
  10 |   HEAD?: Function
  11 |   OPTIONS?: Function


route file:
import { prisma } from "@/lib/prisma";

export function Post(req: Request, res: Response) {
  try {
    const posts = prisma.post.findMany();
    return Response.json({ posts }, { status: 200 });
  } catch (error) {
    return Response.json({ error });
  }
}
Answered by joulev
It has to be POST, full uppercase.

Also remove the res: Response part.
View full answer

2 Replies