Repository: next.js
Issue: Route Handler PATCH export type error in Next.js 15
Labels: TypeScript

### Link to the code that reproduces this issue

https://github.com/shellen/repro-next-route-handler

### To Reproduce

After an npm install of the attached repro, just run `npm run build` to observe a failure to compile:

Linting and checking validity of types  ..Failed to compile.

`src/app/api/test/[id]/route.ts`
`Type error: Route "src/app/api/test/[id]/route.ts" has an invalid "PATCH" export:`
  `Type "{ params: { id: string; }; }" is not a valid type for the function's second argument.`

### Current vs. Expected behavior

# Current: Build fails with type error:

`src/app/api/test/[id]/route.ts`

```
Type error: Route "src/app/api/test/[id]/route.ts" has an invalid "PATCH" export:
  Type "{ params: { id: string; }; }" is not a valid type for the function's second argument.
```
 
# Expected Results:

Build should succeed when using the documented type pattern for route handlers:

```
  export async function PATCH(
    request: NextRequest,
    { params }: { params: { id: string } }
  )
```

  Route handlers in Next.js 15 consistently throw a TypeScript error for the second argument's type, 
  specifically for PATCH methods. This occurs even when following the documented patterns and 
  trying multiple type approaches.

### Provide environment information

```bash
Operating System:
  Platform: linux
  Arch: x64
  Version: #26~22.04.1-Ubuntu SMP Thu Jul 11 22:33:04 UTC 2024
  Available memory (MB): 7930
  Available CPU cores: 2
Binaries:
  Node: 20.18.1
  npm: 10.8.2
  Yarn: 1.22.22
  pnpm: 9.15.0
Relevant Packages:
  next: 15.1.1-canary.13 // Latest available version is detected (15.1.1-canary.13).
  eslint-config-next: 15.1.1
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.7.2
Next.js Config:
  output: N/A
```


### Which area(s) are affected? (Select all that apply)

TypeScript

### Which stage(s) are affected? (Select all that apply)

next build (local)

### Additional context

# Attempted fixes

Here are things I've tried to fix it. 

| Approach | Description | Result | Note |
|----------|-------------|---------|------|
| Custom Props Type | Used Props interface for params | Failed | Type error |
| Props Interface | Added interface for parameters | Failed | Type error |
| Next.js Types | Used NextRequest and return types | Failed | Same type error persisted |
| Base Request Type | Used standard Request type | Failed | Type error remained |
| Record Type | Used Record<string, string \| string[]> | Failed | No improvement |
| Remove Dependencies | Removed @hello-pangea/dnd | Failed | Not dependency related |
| Disable TypedRoutes | Removed from next.config | Failed | Not config related |
| RouteSegment Type | Created custom RouteSegment type | Failed | Type error persisted |
| Runtime Specification | Added nodejs runtime | Failed | No effect on type error |
| Middleware Approach | Added type validation | Failed | Same issue |
| RouteContext Type | Custom context interface | Failed | Invalid second argument |
| NodeJS Runtime + NextRequest | Combined runtime with NextRequest | Failed | Same type error |
| Handler Function Pattern | Separated business logic | Failed | ESLint any error |
| Type Assertion Pattern | Used 'as unknown as' | Failed | Type error remained |
| Custom Route Context | Created RouteContext type | Failed | Not accepted by Next.js |

This table shows systematic attempts to resolve the issue through various typing approaches and configurations, all resulting in the same core type error with the route handler's second argument.

Running React 18 or React 19 does not seem to affect it. We're using a dependency that still needs React 18 but as mentioned, rolling the react version forward didn't seem to fix either.