Unverified Commit dfe08aed authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix NextRequest constructor parameters (#52001)

FIx the type change introduced in #51727
parent 2f42cf55
...@@ -16,7 +16,7 @@ export class NextRequest extends Request { ...@@ -16,7 +16,7 @@ export class NextRequest extends Request {
nextUrl: NextURL nextUrl: NextURL
} }
constructor(input: URL | RequestInfo, init: RequestInit) { constructor(input: URL | RequestInfo, init: RequestInit = {}) {
const url = const url =
typeof input !== 'string' && 'url' in input ? input.url : String(input) typeof input !== 'string' && 'url' in input ? input.url : String(input)
validateURL(url) validateURL(url)
......
/**
* @jest-environment @edge-runtime/jest-environment
*/
import { expectTypeOf } from 'expect-type'
import { NextRequest } from 'next/src/server/web/spec-extension/request'
it('should have 1 required parameter for constructor', () => {
expect(NextRequest.length).toBe(1)
})
it('should allow the 2nd parameter to be undefined', () => {
const request = new NextRequest('https://vercel.com')
expectTypeOf(request).toMatchTypeOf<NextRequest>()
expect(
new NextRequest('https://vercel.com', { geo: { city: 'Mars' } })
).toHaveProperty('geo.city', 'Mars')
expect(new NextRequest('https://vercel.com')).toHaveProperty(
'nextUrl.pathname',
'/'
)
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment