Snippets for Svelte and Svelte-Kit (using TypeScript)
<script lang="ts">
import type { PageData } from './\$types';
export let data: PageData;
$1
</script>
$0
<script>
/** @type {import('./\$types').PageData} */
export let data;
$1
</script>
$0
import type { PageLoad } from './\$types';
export const load: PageLoad = async (${1:event}) => {
$2
return {
$0
};
};
/** @type {import('./\$types').PageLoad} */
export const load = async (${1:event}) => {
$2
return {
$0
};
};
import type { PageServerLoad } from './\$types';
export const load: PageServerLoad = async (${1:event}) => {
$2
return {
$0
};
};
/** @type {import('./\$types').PageServerLoad} */
export const load = async (${1:event}) => {
$2
return {
$0
};
};
import type { LayoutLoad } from './\$types';
export const load: LayoutLoad = async (${1:event}) => {
$2
return {
$0
};
};
/** @type {import('./\$types').LayoutLoad} */
export const load = async (${1:event}) => {
$2
return {
$0
};
};
import type { LayoutServerLoad } from './\$types';
export const load: LayoutServerLoad = async (${1:event}) => {
$2
return {
$0
};
};
/** @type {import('./\$types').LayoutServerLoad} */
export const load = async (${1:event}) => {
$2
return {
$0
};
};
import type { Actions } from './\$types';
export const actions: Actions = {
async ${1:default}({ $2 }) {
$3
}
};
/** @type {import('./\$types').Actions} */
export const actions = {
async ${1:default}({ $1 }) {
$2
}
};
import type { Handle } from '@sveltejs/kit';
export const handle: Handle = async ({ event, resolve }) => {
$1
return resolve(event);
};
/** @type {import('@sveltejs/kit').Handle} */
export const handle = async ({ event, resolve }) => {
$1
return resolve(event);
};
import type { HandleFetch } from '@sveltejs/kit';
export const handle: HandleFetch = async ({ request, fetch }) => {
$1
return resolve(request);
};
/** @type {import('@sveltejs/kit').HandleFetch} */
export const handle = async ({ request, fetch }) => {
$1
};
import type { HandleError } from '@sveltejs/kit';
export const handle: HandleError = async ({ error, event }) => {
$2
};
/** @type {import('@sveltejs/kit').HandleError} */
export const handle = async ({ error, event }) => {
$1
};
import type { RequestHandler } from './\$types';
export const GET = (async ({ $1 }) => {
$2
return new Response('Ok', { status: 200 });
}) satisfies RequestHandler;
let { $2 } = \$props()
type Props = {
$1
};
let { $2 }: Props = \$props()
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher<{ $1: $2}>()
$0
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher()
$0
<script lang="ts">
$1
</script>
$0
<script>
$1
</script>
$0
<svelte:head>
$1
</svelte:head>
$0
{#each $1 as $2 ($3)}
$0
{/each}
$0
{#each $1 as $2 ($3)}
$4
{:else}
$5
{/each}
$0
{#if $1}
$2
{/if}
$0
{#if $1}
$2
{:else}
$3
{/if}
$0
{#if $1}
$2
{:else if $3}
$4
{/if}
$0
{#await $1}
$2
{:then $3}
$4
{/await}
$0
{#key $1}
$2
{/key}
$0
The snippets include "$1", "$2"... which are placeholders for the cursor position. You can use the tab key to jump between them.
MIT