Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

How Do I Add TypeScript to a SvelteKit Handle Function in Hooks?

$
0
0

I am currently using the following in my hooks.ts file in a SvelteKit app:

export async function handle({ event, resolve }) {  console.log(event.locals) //<-- Works fine}

I'm trying to figure out how to use types on the event and resolve parameters. As far as I can tell, event works like this:

import type { RequestEvent } from '@sveltejs/kit'export async function handle(event: RequestEvent, resolve: ???){  ...}

But I can't figure out how to type the resolve parameter. The docs here show this:

interface Handle {  (input: {    event: RequestEvent;    resolve(      event: RequestEvent,      opts?: ResolveOptions    ): MaybePromise<Response>;  }): MaybePromise<Response>;}

From my limited TypeScript knowledge, it looks like resolve is a function with two parameters that returns a promise. But how do I write that out in the handle function declaration?


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>