Sveltekitcookies type error

When I add following code
export const auth = betterAuth({
// ... your config
plugins: [sveltekitCookies(getRequestEvent)],
});
export const auth = betterAuth({
// ... your config
plugins: [sveltekitCookies(getRequestEvent)],
});
I get error
Argument of type '() => RequestEvent<Partial<Record<string, string>>, string | null>' is not assignable to parameter of type '() => Promise<RequestEvent<Partial<Record<string, string>>, string | null>>'.
Type 'RequestEvent<Partial<Record<string, string>>, string | null>' is missing the following properties from type 'Promise<RequestEvent<Partial<Record<string, string>>, string | null>>': then, catch, finally, [Symbol.toStringTag]
Argument of type '() => RequestEvent<Partial<Record<string, string>>, string | null>' is not assignable to parameter of type '() => Promise<RequestEvent<Partial<Record<string, string>>, string | null>>'.
Type 'RequestEvent<Partial<Record<string, string>>, string | null>' is missing the following properties from type 'Promise<RequestEvent<Partial<Record<string, string>>, string | null>>': then, catch, finally, [Symbol.toStringTag]
How do I fix this error?
2 Replies
Duki
Duki2mo ago
I got the same error I guess for now you can either ignore this error like this:
// @ts-expect-error sveltekitCookies expects getRequestEvent to return a promise, but it doesn't
plugins: [sveltekitCookies(getRequestEvent)],
// @ts-expect-error sveltekitCookies expects getRequestEvent to return a promise, but it doesn't
plugins: [sveltekitCookies(getRequestEvent)],
Or just cast it, like this:
sveltekitCookies(getRequestEvent as unknown as () => Promise<RequestEvent>)
sveltekitCookies(getRequestEvent as unknown as () => Promise<RequestEvent>)
I personally would recommend doing it the // @ts-expect-error way (first example), because once this gets fixed, you're IDE will add a red squiggly line there, saying that your expecting an error, but there is none, so you can safely remove that comment afterwards. The cast is a bit more stealth-ish and will potentially stay there even after it's been fixed. But despite this TS error, does the plugin work fine for you? I haven't tested it yet myself, just started migrating now.
Robi
Robi2mo ago
Hey there , this has been fixed and will soon be pushed out to the beta release 🙏🏼

Did you find this page helpful?