I’m currently learning Sveltekit following the official tutorial. The tutorials are clear and straightforward. But I got stuck on this page of the tutorial when I tried to mix in some typescript with the load function.
When I use the arrow function, everything checks perfectly:
import type { PageServerLoad } from './$types'
import { posts } from './data'
export const load: PageServerLoad = () => {
return {
summaries: posts.map(post => ({
slug: post.slug,
title: post.title,
}))
}
}
But when I use the regular function, I get this error 'summaries' does not exist in type 'PageLoad'
:
import type { PageServerLoad } from './$types'
import { posts } from './data'
export function load(): PageServerLoad {
return {
summaries: posts.map(post => ({
slug: post.slug,
title: post.title,
}))
}
}
I thought these two functions were equivalent. Did I miss something? Thanks