kit icon indicating copy to clipboard operation
kit copied to clipboard

Forced cookie path change breaks re-use of CookieSerializeOptions

Open hmnd opened this issue 1 year ago • 1 comments

Describe the bug

The event.cookies.[get/set/delete] options type is no longer compatible with the CookieSerializeOptions type from cookie, with no alternative type provided by @sveltejs/kit.

Reproduction

const cookieOptions: CookieSerializeOptions = { path: base || '/', secure: true };
event.cookies.delete('session_id', cookieOptions);
event.cookies.delete('access_token', cookieOptions);
event.cookies.delete('refresh_token', cookieOptions);

results in this error:

Argument of type 'CookieSerializeOptions' is not assignable to parameter of type 'CookieSerializeOptions & { path: string; }'.
  Type 'CookieSerializeOptions' is not assignable to type '{ path: string; }'.
    Types of property 'path' are incompatible.
      Type 'string | undefined' is not assignable to type 'string'.
        Type 'undefined' is not assignable to type 'string'.

Logs

No response

System Info

System:
    OS: Linux 6.6 Manjaro Linux
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 8.15 GB / 15.54 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.asdf/installs/nodejs/20.10.0/bin/node
    npm: 10.2.3 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 8.14.0 - ~/.local/share/pnpm/pnpm
  Browsers:
    Brave Browser: 121.1.62.153
    Chromium: 120.0.6099.129

Severity

annoyance

Additional Information

Change happened in Ideally, SvelteKit should export its own CookieSerializeOptions, to make such reuse of options more ergonomic.

hmnd avatar Feb 04 '24 23:02 hmnd

A good workaround for now is to use the satisfies keyword for a more accurate type https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-9.html wondering if this should just be the definitive solution

teemingc avatar Feb 10 '24 15:02 teemingc