In my SvelteKit application's hooks.ts
file, I currently have the following code:
export async function handle({ event, resolve }) {
console.log(event.locals) //<-- Works fine
}
I am now exploring how to implement types for the event
and resolve
parameters. Based on my understanding, the event
parameter can be typed as follows:
import type { RequestEvent } from '@sveltejs/kit'
export async function handle(event: RequestEvent, resolve: ???){
...
}
However, I am struggling to determine how to type the resolve
parameter. The documentation provides this example:
interface Handle {
(input: {
event: RequestEvent;
resolve(
event: RequestEvent,
opts?: ResolveOptions
): MaybePromise<Response>;
}): MaybePromise<Response>;
}
Based on my knowledge of TypeScript, it seems like resolve
is a function with two parameters that returns a promise. How should I incorporate this into the declaration of the handle
function?