Replies: 2 comments 5 replies
-
I don't use Typescript and I have the same problems. I'm doing the following to avoid renaming my variables (I'm using let loadedData
export { loadedData as data}
let { data } = loadedData
$: ({ data } = loadedData) |
Beta Was this translation helpful? Give feedback.
-
I think one thing to consider is that a page in SvelteKit can be thought of as a higher-order component: it is composed of specialised Svelte components. This is a pattern that I use: #./src/routes/posts/[id]/+page.svelte
<script lang="ts">
import type { PageData } from './$types';
import Post from '$lib/components/Post.svelte';
export let data: PageData;
/* PageData: { post: { slug: string, title: string, ... }, ... } */
</script>
<Post {...data.post} /> #./src/lib/components/Post.svelte
<script lang="ts">
export let slug: string;
export let title: string;
</script>
<h1>{title}</h1> This might seem a trivial example (and it is) but when #./src/routes/posts/[id]/+page.svelte
<script lang="ts">
import type { PageData } from './$types';
import Post from '$lib/components/Post.svelte';
export let data: PageData;
/* PageData: { post: { slug: string, title: string, ... }, banner: { src: string }, ... } */
</script>
{#if data.banner}
<Banner {...data.banner} />
{/if}
<Post {...data.post} /> |
Beta Was this translation helpful? Give feedback.
-
I really like the new design changes, but i have to say this one is causing me troubles :
First, it adds boilerplates code by using not-so-pretty destructuring assignment
Secondly,
data
is a common variable name i personnaly use a lot in my page logic. So now i can't use something likeanywhere in my code because it will cause conflict with page data. And even without that, i will now see a lot of
data.foo.data
or evendata.data
in my code, which looks pretty bad in my opinion.Lastly, i'm not sure why this change was needed. I understand it is a matter of type checking but as a non-user of typescript i don't see the benefits ot it, for me it adds only unnecessary complexity.
I dont know, maybe i'm the only one bothered...
Anyway, thanks for reading me
Beta Was this translation helpful? Give feedback.
All reactions