import { MaybeRefOrGetter, Ref } from "vue"; export type CookiesGetMethodType = (name: string) => T; // what get() hands back: a String, or the Object/Array a JSON cookie holds type CookieValue = string | object; /** * The typed cookie names, for `useCookie()`. Augment it once to have * your cookies checked at every call: * * declare module "quasar" { * interface CookieValues { * theme: "light" | "dark"; * } * } * * A cookie that is not declared accepts any cookie value; its default, * when given, sets the type by what it returns. */ // oxlint-disable-next-line typescript/no-empty-object-type export interface CookieValues {} export interface CookieRefOptions { default?: () => T; deep?: boolean; disabled?: MaybeRefOrGetter; expires?: number | string | Date; path?: string; domain?: string; sameSite?: "Lax" | "Strict" | "None"; httpOnly?: boolean; secure?: boolean; other?: string; } // what a default types the ref as: a String default leaves every // String assignable (declare the cookie in CookieValues for a union) type CookieValueOf = T extends string ? string : T; // assigning null removes the cookie (or resets it to the default) export type CookieRef = Ref & { stop: () => void; }; export interface CookiesUseCookieMethodType { ( name: K, options: CookieRefOptions & { default: () => CookieValues[K]; } ): CookieRef; ( name: K, options?: CookieRefOptions ): CookieRef; ( name: K extends keyof CookieValues ? never : K, options: CookieRefOptions & { default: () => T } ): CookieRef>; ( name: K extends keyof CookieValues ? never : K, options?: CookieRefOptions ): CookieRef; }