Type Errors with `next@12.2.0`
paulmolluzzo opened this issue · comments
There is a TS error when upgrading next
to >=12.2.0
:
Type error: Type 'IncomingMessage & { cookies: Partial<{ [key: string]: string; }>; }' is not assignable to type '(IncomingMessage & { cookies?: { [key: string]: string; } | undefined; }) | undefined'.
Type 'IncomingMessage & { cookies: Partial<{ [key: string]: string; }>; }' is not assignable to type 'IncomingMessage & { cookies?: { [key: string]: string; } | undefined; }'.
Type 'IncomingMessage & { cookies: Partial<{ [key: string]: string; }>; }' is not assignable to type '{ cookies?: { [key: string]: string; } | undefined; }'.
Types of property 'cookies' are incompatible.
Type 'Partial<{ [key: string]: string; }>' is not assignable to type '{ [key: string]: string; }'.
'string' index signatures are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
Next updated their cookies recently, which might be the reason for this: https://nextjs.org/docs/messages/middleware-upgrade-guide#cookies-api-revamped
I believe it stems from this library here:
Lines 6 to 8 in d87cd88
Did you try to use library in middleware?
cookies-next hasn't supported using in middleware yet.
Please, work with cookies like next.js docs
I will try to add supporting it in next versions
I was trying to use the package to support middleware, yes. I didn't realize there wasn't official support for that use case. 😅
In the meantime I was able to resolve the issue by directly consuming the cookies, and look forward to the update.
Thanks for this package and the detailed reply! 🙌