diff --git a/packages/next/server/web/spec-extension/cookies.ts b/packages/next/server/web/spec-extension/cookies.ts index 6c152e1f483373f..125cf7d30a3670d 100644 --- a/packages/next/server/web/spec-extension/cookies.ts +++ b/packages/next/server/web/spec-extension/cookies.ts @@ -2,10 +2,9 @@ import type { CookieSerializeOptions } from '../types' import cookie from 'next/dist/compiled/cookie' -type GetWithOptionsOutput = { +export interface Cookie extends CookieSerializeOptions { /** A `string` representing the value of the cookie. */ value: string | undefined - options: CookieSerializeOptions } const normalizeCookieOptions = (options: CookieSerializeOptions) => { @@ -72,18 +71,17 @@ export class NextCookies extends Cookies { get(...args: Parameters) { return this.getWithOptions(...args).value } - getAll(): GetWithOptionsOutput[] { - const all: GetWithOptionsOutput[] = [] + getAll(): Cookie[] { + const all: Cookie[] = [] for (const key of this.keys()) { all.push(this.getWithOptions(key)) } return all } - getWithOptions(...args: Parameters): GetWithOptionsOutput { + getWithOptions(...args: Parameters): Cookie { const raw = super.get(...args) - if (typeof raw !== 'string') return { value: raw, options: {} } - const { [args[0]]: value, ...options } = cookie.parse(raw) - return { value, options } + if (typeof raw !== 'string') return { value: raw } + return cookie.parse(raw) as unknown as Cookie } set(...args: Parameters) { const isAlreadyAdded = super.has(args[0])