iron-session icon indicating copy to clipboard operation
iron-session copied to clipboard

outdated dependency @types/cookie causes type mismatch

Open brumm opened this issue 1 year ago • 1 comments

Hey there,

I'm seeing a TS error when passing Nextjs's cookies() function to getIronSession

Argument of type 'ReadonlyRequestCookies' is not assignable to parameter of type 'CookieStore'.
  Types of property 'set' are incompatible.
    Type '(...args: [key: string, value: string, cookie?: Partial<ResponseCookie> | undefined] | [options: ResponseCookie]) => ResponseCookies' is not assignable to type '{ (name: string, value: string, cookie?: Partial<ResponseCookie> | undefined): void; (options: ResponseCookie): void; }'.
      Types of parameters 'args' and 'name' are incompatible.
        Type '[name: string, value: string, cookie?: Partial<ResponseCookie> | undefined]' is not assignable to type '[key: string, value: string, cookie?: Partial<ResponseCookie> | undefined] | [options: ResponseCookie]'.
          Type '[name: string, value: string, cookie?: Partial<ResponseCookie> | undefined]' is not assignable to type '[key: string, value: string, cookie?: Partial<ResponseCookie> | undefined]'.
            Type at position 2 in source is not compatible with type at position 2 in target.
              Type 'Partial<ResponseCookie> | undefined' is not assignable to type 'Partial<import("/Users/brumm/Code/portals/node_modules/next/dist/compiled/@edge-runtime/cookies/index").ResponseCookie> | undefined'.
                Type 'Partial<ResponseCookie>' is not assignable to type 'Partial<import("/Users/brumm/Code/portals/node_modules/next/dist/compiled/@edge-runtime/cookies/index").ResponseCookie>'.
                  Types of property 'priority' are incompatible.
                    Type 'unknown' is not assignable to type '"low" | "medium" | "high" | undefined'.ts(2345)

It seems like the priority attribute has been added to the types in @types/[email protected], but this library is still on 0.5.4

brumm avatar Jan 12 '24 15:01 brumm

Hey there,

I'm seeing a TS error when passing Nextjs's cookies() function to getIronSession

Argument of type 'ReadonlyRequestCookies' is not assignable to parameter of type 'CookieStore'.
  Types of property 'set' are incompatible.
    Type '(...args: [key: string, value: string, cookie?: Partial<ResponseCookie> | undefined] | [options: ResponseCookie]) => ResponseCookies' is not assignable to type '{ (name: string, value: string, cookie?: Partial<ResponseCookie> | undefined): void; (options: ResponseCookie): void; }'.
      Types of parameters 'args' and 'name' are incompatible.
        Type '[name: string, value: string, cookie?: Partial<ResponseCookie> | undefined]' is not assignable to type '[key: string, value: string, cookie?: Partial<ResponseCookie> | undefined] | [options: ResponseCookie]'.
          Type '[name: string, value: string, cookie?: Partial<ResponseCookie> | undefined]' is not assignable to type '[key: string, value: string, cookie?: Partial<ResponseCookie> | undefined]'.
            Type at position 2 in source is not compatible with type at position 2 in target.
              Type 'Partial<ResponseCookie> | undefined' is not assignable to type 'Partial<import("/Users/brumm/Code/portals/node_modules/next/dist/compiled/@edge-runtime/cookies/index").ResponseCookie> | undefined'.
                Type 'Partial<ResponseCookie>' is not assignable to type 'Partial<import("/Users/brumm/Code/portals/node_modules/next/dist/compiled/@edge-runtime/cookies/index").ResponseCookie>'.
                  Types of property 'priority' are incompatible.
                    Type 'unknown' is not assignable to type '"low" | "medium" | "high" | undefined'.ts(2345)

It seems like the priority attribute has been added to the types in @types/[email protected], but this library is still on 0.5.4

hello sir. I got the same error. how do you solve that?

aryaadinulfadlan avatar Mar 24 '24 12:03 aryaadinulfadlan

Hello, I got the same error. How do we solve that?

murieldelvaux avatar Jun 03 '24 18:06 murieldelvaux

I couldn't find a better way other than just use type assertion, ugly I know:

await getIronSession<SessionData>(cookies() as any, config)

mordechaim avatar Jun 03 '24 18:06 mordechaim

I tried something similar, it worked, thank you very much!

murieldelvaux avatar Jun 03 '24 18:06 murieldelvaux

Hey there, I upgraded cookies to 0.6.0 this should be solved? Let me know!

vvo avatar Jun 14 '24 13:06 vvo

8.0.2 was released

vvo avatar Jun 14 '24 13:06 vvo

Hello, I just updated to test, but I still get the same thing: "Argument of Type" Readonlyrequestcookies 'is not asquisignable to parameter of type' cookiestore'.ts (2345) âš  Error (TS2345) | ARGUENT OF TYPE is not assignable to parameter of type . "

To solve this, I had to keep it as in the image below: image

murieldelvaux avatar Jun 14 '24 15:06 murieldelvaux

@murieldelvaux Is there any chance you can create a simple github repository showing the issue? I do not get the problem currently.

vvo avatar Jun 14 '24 16:06 vvo

I was able to resolve this by directly depending on @types/cookie in my project.

robknight avatar Jun 20 '24 19:06 robknight