I'm creating a middleware that adds a "name" property to NextRequest, this property will be used in other parts of the API
import { NextRequest, NextResponse } from 'next/server'
export function middleware(req: NextRequest) {
req.name = 'Foo'
NextResponse.next()
}
I get this error Property 'name' does not exist on type 'NextRequest'
An alternative would be to create an interface that extends NextRequest, but I would have to import all files that want to access the "name" property
import { NextRequest, NextResponse } from 'next/server'
interface CustomRequest extends NextRequest {
name: string
}
export function middleware(req: CustomRequest) {
req.name = 'Foo'
NextResponse.next()
}
Is there any way to add this property into NextRequest global types?