I'm currently working on a middleware that will introduce a new "name" property to NextRequest. This specific property is intended for use in other sections of the API.
import { NextRequest, NextResponse } from 'next/server'
export function applyMiddleware(req: NextRequest) {
req.name = 'Foo'
NextResponse.next()
}
Encountering the error message
Property 'name' does not exist on type 'NextRequest'
One possible solution could involve creating an interface that extends NextRequest. However, this approach would require importing all files that need access to the "name" property.
import { NextRequest, NextResponse } from 'next/server'
interface CustomRequest extends NextRequest {
name: string
}
export function applyMiddleware(req: CustomRequest) {
req.name = 'Foo'
NextResponse.next()
}
Is there a method to incorporate this property into the global types of NextRequest?