Unverified Commit a47d47e0 authored by Andre Hsu's avatar Andre Hsu Committed by GitHub

Change type of GetServerSidePropsContext.req.cookies the be the same as…

Change type of GetServerSidePropsContext.req.cookies the be the same as NextApiRequest.cookies (#21336)

The original type for `GetServerSidePropsContext.req.cookies` was introduced in #19724. In the PR, the test at `test/integration/typescript/test/index.test.js` expects req.cookies to always exist, so `req.cookies` will never be undefined.

I'm guessing that req.cookies is parsed using the same cookie middleware as `NextApiRequest`, in which case `req.cookies` should be `{ [key: string]: string }`, not `{ [key: string]: any }`.
parent f6cc0ded
...@@ -44,7 +44,11 @@ import { ...@@ -44,7 +44,11 @@ import {
NextComponentType, NextComponentType,
RenderPage, RenderPage,
} from '../lib/utils' } from '../lib/utils'
import { tryGetPreviewData, __ApiPreviewProps } from './api-utils' import {
tryGetPreviewData,
NextApiRequestCookies,
__ApiPreviewProps,
} from './api-utils'
import { denormalizePagePath } from './denormalize-page-path' import { denormalizePagePath } from './denormalize-page-path'
import { FontManifest, getFontDefinitionFromManifest } from './font-utils' import { FontManifest, getFontDefinitionFromManifest } from './font-utils'
import { LoadComponentsReturnType, ManifestItem } from './load-components' import { LoadComponentsReturnType, ManifestItem } from './load-components'
...@@ -796,7 +800,9 @@ export async function renderToHTML( ...@@ -796,7 +800,9 @@ export async function renderToHTML(
try { try {
data = await getServerSideProps({ data = await getServerSideProps({
req, req: req as IncomingMessage & {
cookies: NextApiRequestCookies
},
res, res,
query, query,
resolvedUrl: renderOpts.resolvedUrl as string, resolvedUrl: renderOpts.resolvedUrl as string,
......
...@@ -15,6 +15,11 @@ import { ...@@ -15,6 +15,11 @@ import {
// @ts-ignore This path is generated at build time and conflicts otherwise // @ts-ignore This path is generated at build time and conflicts otherwise
} from '../dist/next-server/lib/utils' } from '../dist/next-server/lib/utils'
import {
NextApiRequestCookies,
// @ts-ignore This path is generated at build time and conflicts otherwise
} from '../dist/next-server/server/api-utils'
// @ts-ignore This path is generated at build time and conflicts otherwise // @ts-ignore This path is generated at build time and conflicts otherwise
import next from '../dist/server/next' import next from '../dist/server/next'
...@@ -130,7 +135,7 @@ export type GetServerSidePropsContext< ...@@ -130,7 +135,7 @@ export type GetServerSidePropsContext<
Q extends ParsedUrlQuery = ParsedUrlQuery Q extends ParsedUrlQuery = ParsedUrlQuery
> = { > = {
req: IncomingMessage & { req: IncomingMessage & {
cookies?: { [key: string]: any } cookies: NextApiRequestCookies
} }
res: ServerResponse res: ServerResponse
params?: Q params?: Q
......
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