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

fix NextApiRequestCookies and NextApiRequestQuery types #25532

Merged
merged 3 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/next/server/api-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { BaseNextRequest } from '../base-http'

import { NextApiRequest, NextApiResponse } from '../../shared/lib/utils'

export type NextApiRequestCookies = { [key: string]: string }
export type NextApiRequestQuery = { [key: string]: string | string[] }
export type NextApiRequestCookies = Partial<{ [key: string]: string }>
export type NextApiRequestQuery = Partial<{ [key: string]: string | string[] }>

export type __ApiPreviewProps = {
previewModeId: string
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/api-utils/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function tryGetPreviewData(
return false
}

const tokenPreviewData = cookies[COOKIE_NAME_PRERENDER_DATA]
const tokenPreviewData = cookies[COOKIE_NAME_PRERENDER_DATA] as string

let encryptedPreviewData: {
data: string
Expand Down
4 changes: 2 additions & 2 deletions packages/next/shared/lib/i18n/get-locale-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { normalizeLocalePath } from './normalize-locale-path'
import type { I18NConfig, DomainLocale } from '../../../server/config-shared'

interface Params {
cookies(): { [key: string]: string }
cookies(): Partial<{ [key: string]: string }>
headers?: { [key: string]: string | string[] | undefined }
nextConfig: { basePath?: string; i18n: I18NConfig; trailingSlash?: boolean }
url: { hostname?: string | null; pathname: string }
Expand Down Expand Up @@ -48,7 +48,7 @@ export function getLocaleMetadata(params: Params) {

function getLocaleFromCookie(
i18n: I18NConfig,
cookies: () => { [key: string]: string }
cookies: () => Partial<{ [key: string]: string }>
) {
const nextLocale = cookies()?.NEXT_LOCALE?.toLowerCase()
return nextLocale
Expand Down
8 changes: 4 additions & 4 deletions packages/next/shared/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ export interface NextApiRequest extends IncomingMessage {
/**
* Object of `query` values from url
*/
query: {
query: Partial<{
[key: string]: string | string[]
}
}>
/**
* Object of `cookies` from header
*/
cookies: {
cookies: Partial<{
[key: string]: string
}
}>

body: any

Expand Down