Skip to content

Typesafe wrapper around load functions #9180

Answered by cdcarson
nick-lehmann asked this question in Q&A
Discussion options

You must be logged in to vote

I've struggled with this too, though in my case I wrap action functions (for reasons that we need not go into.) I think the issue is that some of the generated types (RequestEvent, PageServerLoad, etc.) are perhaps over-typed and/or include unhelpful default types. I've considered filing an issue, but I'm not really sure that there's a better solution.

Whatever the case, it requires your wrapper function to be similarly typed. So, you can get around the typescript errors but at the expense of a bit of ugliness and verbosity. For your example above, here's what seems to work (i.e. typescript doesn't complain, and SvelteKit infers the correct shape of PageData back into ./$types.) Do this f…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@cdcarson
Comment options

@nick-lehmann
Comment options

@KiraPC
Comment options

@cdcarson
Comment options

@KiraPC
Comment options

Answer selected by nick-lehmann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants