fix(next): update rest route handler types for Next.js 15.5 compatibility (#13521)
Fixes #13527. When upgrading to [Next.js 15.5](https://nextjs.org/blog/next-15-5) with Payload, you might experience a runtime or build error similar to this: ```ts Type error: Type 'typeof import("/src/app/(payload)/api/graphql/route")' does not satisfy the expected type 'RouteHandlerConfig<"/api/graphql">'. Types of property 'OPTIONS' are incompatible. Type '(request: Request, args: { params: Promise<{ slug: string[]; }>; }) => Promise<Response>' is not assignable to type '(request: NextRequest, context: { params: Promise<{}>; }) => void | Promise<void> | Response | Promise<Response>'. Types of parameters 'args' and 'context' are incompatible. Type '{ params: Promise<{}>; }' is not assignable to type '{ params: Promise<{ slug: string[]; }>; }'. Types of property 'params' are incompatible. Type 'Promise<{}>' is not assignable to type 'Promise<{ slug: string[]; }>'. Property 'slug' is missing in type '{}' but required in type '{ slug: string[]; }'. ``` This is because Next.js route types are now _stricter_. Our REST handler is nested within a catch-all `/api/[...slug]` route, so the slug param _will_ exist in the handler—but the _same_ handler is re-used for the `/api/graphql` OPTIONS route, which **_is not_** nested within the `slug` param and so it **_will not_** exist as the types suggest. --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1211115021865680 --------- Co-authored-by: Jacob Fletcher <jacobsfletch@gmail.com>
This commit is contained in:
@@ -9,7 +9,7 @@ const handlerBuilder =
|
||||
async (
|
||||
request: Request,
|
||||
args: {
|
||||
params: Promise<{ slug: string[] }>
|
||||
params: Promise<{ slug?: string[] }>
|
||||
},
|
||||
): Promise<Response> => {
|
||||
const awaitedConfig = await config
|
||||
|
||||
@@ -3,18 +3,11 @@ import { getPayload } from 'payload'
|
||||
|
||||
import { draftMode } from 'next/headers'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { NextRequest } from "next/server"
|
||||
|
||||
import configPromise from '@payload-config'
|
||||
|
||||
export async function GET(
|
||||
req: {
|
||||
cookies: {
|
||||
get: (name: string) => {
|
||||
value: string
|
||||
}
|
||||
}
|
||||
} & Request,
|
||||
): Promise<Response> {
|
||||
export async function GET(req: NextRequest): Promise<Response> {
|
||||
const payload = await getPayload({ config: configPromise })
|
||||
|
||||
const { searchParams } = new URL(req.url)
|
||||
|
||||
@@ -3,18 +3,11 @@ import { getPayload } from 'payload'
|
||||
|
||||
import { draftMode } from 'next/headers'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { NextRequest } from "next/server"
|
||||
|
||||
import configPromise from '@payload-config'
|
||||
|
||||
export async function GET(
|
||||
req: {
|
||||
cookies: {
|
||||
get: (name: string) => {
|
||||
value: string
|
||||
}
|
||||
}
|
||||
} & Request,
|
||||
): Promise<Response> {
|
||||
export async function GET(req: NextRequest): Promise<Response> {
|
||||
const payload = await getPayload({ config: configPromise })
|
||||
|
||||
const { searchParams } = new URL(req.url)
|
||||
|
||||
Reference in New Issue
Block a user