skn-svelte-types Svelte Themes

Skn Svelte Types

A Simple Type Definition Extension Library For Svelte Kit (Svelte 5)

SKN Svelte Kit (Svelte 5) Type Extension Library

svelte

TypeScript Svelte

 

Introduction:

This is a simple TypeScript Type Extension Library for Svelte Kit (Svelte 5)

I made this library so that I can use it in all of my Svelte Kit (Svelte 5) projects without writing the same codes over and over again

 

Details:

SveltePageDataProps Type

  • Provides page server data type for svelte rune $props()
  • This type is intended to be used only in +page.svelte
  • For usage instruction, see Usage section

SveltePageLayoutProps Type

  • Provides page layout data type for svelte rune $props()
  • This type is intended to be used only in +layout.svelte
  • For usage instruction, see Usage section

 

Use Case:

  • Svelte Kit

 

Requirements:

This library has peer dependency for Svelte of minimum 5.0.2. It may or may not work on 6.x

This library is intended to be used in Svelte Kit of minimum 2.7.2. It may or may not work on 3.x

 

Usage:

To install the package, type the following in console

npm add -D @best-skn/svelte-types
#or
yarn add -D @best-skn/svelte-types
#or
pnpm add -D @best-skn/svelte-types
#or
bun add -D @best-skn/svelte-types

Create a directory called types in the root location of your project, and create a file called svelte.d.ts, then do this

import "@best-skn/svelte-types";

Check your tsconfig.json if includes property has **/*.ts, **/*.tsx, **/*.svelte otherwise the type definition file may not work

Now Inside your Svelte Kit (Svelte 5) Project, use the package like this (Just an example)

SveltePageDataProps Type:

Import & use SveltePageDataProps inside +page.svelte like this
//* `+page.svelte`
<script lang="ts">
 import type { SveltePageDataProps } from "@sveltejs/kit";
 import type { PageServerData } from "./$types";

 let { data }: SveltePageDataProps<PageServerData> = $props();
</script>

SveltePageLayoutProps Type:

Import & use SveltePageLayoutProps inside +layout.svelte like this
//* `+layout.svelte`
<script lang="ts">
 import type { SveltePageLayoutProps } from "@sveltejs/kit";

 let { children, data, row }: SveltePageLayoutProps<unknown> = $props();
</script>

<div>
 <main>
   {@render children()}
 </main>
</div>

 

Dedicated To:

  • ๐Ÿ‘ฉโ€โš•๏ธTanjila Hasan Trina: The long lost love of my life. The course of nature separated us from our paths and put us in separate places far away from each other. But no matter how separated we are right now, each and every moment of mine is only dedicated to you. We may not see each other in this lifetime as it seems but I will find you again in the next life. I just want to say: ไธ–็•Œใฏๆฎ‹้…ทใ  ใใ‚Œใงใ‚‚ๅ›ใ‚’ๆ„›ใ™ใ‚ˆ
  • ๐Ÿ’ฏMy Parents: The greatest treasures of my life ever.

 

License:

Copyright (C) 2024 SKN Shukhan

Licensed under the MIT License

Top categories

Loading Svelte Themes