You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
📋 Description of content that is out-of-date or incorrect
Given example does not work anymore and is likely due to being outdated, because the Astro.cookies.set("counter",counter) accepts types key: string, value: string | Record<string, any>, options?: AstroCookieSetOptions instead of (key: string, value: string | number | boolean | object, options?: CookieSetOptions) => void. Example works only for npm run dev, but fails with npm run build with TypeScript error 2345.
Also to note, there's also TypeScript error 2532, as the cookie value in const cookie = Astro.cookies.get("counter") might be undefined and fixed with !. parameter like so const cookie = Astro.cookies!.get("counter").
Working basic example using Record type, compiles without error nor warnings.
---// Create the Record TypeinterfaceCookieData{exampleString: string;
counter: number;}// Create the Example DataletCookieDataExample: CookieData={exampleString: "example",counter: 0,}letcounterFromCookie=-1if(Astro.cookies.has("counter")){console.log("cookie exists")constcookie=Astro.cookies.get("counter")// Parse as JSON data and get the counter valueconsole.log(cookie!.json())counterFromCookie=cookie!.json().counterCookieDataExample.counter=counterFromCookie+1}Astro.cookies.set("counter",CookieDataExample)---<html><h1>Counter={CookieDataExample.counter}</h1></html>
🖥️ Reproduction in StackBlitz (if reporting incorrect content or code samples)
No response
The text was updated successfully, but these errors were encountered:
Also apologies if not using reproduction in StackBlitz, as I am new to web development for hobby purposes!
Line let counterFromCookie = -1 is used as an definer, but -1 value for debugging and educational line to note that the implementation uses the cookies' value instead of the local variable.
📚 Subject area/topic
On-demand Rendering Adapters @ Cookies
📋 Page(s) affected (or suggested, for new content)
https://docs.astro.build/en/guides/server-side-rendering/#cookies
https://docs.astro.build/en/reference/api-reference/#set
📋 Description of content that is out-of-date or incorrect
Given example does not work anymore and is likely due to being outdated, because the
Astro.cookies.set("counter",counter)
accepts typeskey: string, value: string | Record<string, any>, options?: AstroCookieSetOptions
instead of(key: string, value: string | number | boolean | object, options?: CookieSetOptions) => void
. Example works only fornpm run dev
, but fails withnpm run build
with TypeScript error 2345.Also to note, there's also TypeScript error 2532, as the
cookie
value inconst cookie = Astro.cookies.get("counter")
might be undefined and fixed with!.
parameter like soconst cookie = Astro.cookies!.get("counter")
.Broken example:
Working basic example using Record type, compiles without error nor warnings.
🖥️ Reproduction in StackBlitz (if reporting incorrect content or code samples)
No response
The text was updated successfully, but these errors were encountered: