Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional generic parameter to NextResponse #47526

Merged
merged 10 commits into from
May 19, 2023
8 changes: 6 additions & 2 deletions packages/next/src/server/web/spec-extension/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ function handleMiddlewareField(
}
}

export class NextResponse extends Response {
export class NextResponse<Body = unknown> extends Response {
[INTERNALS]: {
cookies: ResponseCookies
url?: NextURL
body?: Body
}

constructor(body?: BodyInit | null, init: ResponseInit = {}) {
Expand Down Expand Up @@ -66,7 +67,10 @@ export class NextResponse extends Response {
return this[INTERNALS].cookies
}

static json(body: any, init?: ResponseInit): NextResponse {
static json<JsonBody>(
body: JsonBody,
init?: ResponseInit
): NextResponse<JsonBody> {
// @ts-expect-error This is not in lib/dom right now, and we can't augment it.
const response: Response = Response.json(body, init)
return new NextResponse(response.body, response)
Expand Down