From 085301728b87228d631cf838ecae581e92691e47 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 18 Dec 2024 16:56:20 +0000 Subject: [PATCH] types + changeset --- .changeset/popular-walls-fetch.md | 5 +++++ packages/svelte/src/ambient.d.ts | 8 ++++++-- packages/svelte/types/index.d.ts | 8 ++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 .changeset/popular-walls-fetch.md diff --git a/.changeset/popular-walls-fetch.md b/.changeset/popular-walls-fetch.md new file mode 100644 index 0000000000..68e1b6d42e --- /dev/null +++ b/.changeset/popular-walls-fetch.md @@ -0,0 +1,5 @@ +--- +'svelte': minor +--- + +feat: pass AbortSignal to effects and allow async signature diff --git a/packages/svelte/src/ambient.d.ts b/packages/svelte/src/ambient.d.ts index 5297cb6c32..87ba0a70a6 100644 --- a/packages/svelte/src/ambient.d.ts +++ b/packages/svelte/src/ambient.d.ts @@ -234,7 +234,9 @@ declare namespace $derived { * https://svelte.dev/docs/svelte/$effect * @param fn The function to execute */ -declare function $effect(fn: (input: { signal: AbortSignal }) => void | ((input: { signal: AbortSignal }) => void)): void; +declare function $effect( + fn: (input: { signal: AbortSignal }) => void | (() => void) | Promise +): void; declare namespace $effect { /** @@ -253,7 +255,9 @@ declare namespace $effect { * https://svelte.dev/docs/svelte/$effect#$effect.pre * @param fn The function to execute */ - export function pre(fn: (input: { signal: AbortSignal }) => void | ((input: { signal: AbortSignal }) => void)): void; + export function pre( + fn: (input: { signal: AbortSignal }) => void | (() => void) | Promise + ): void; /** * The `$effect.tracking` rune is an advanced feature that tells you whether or not the code is running inside a tracking context, such as an effect or inside your template. diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index 80c80a0e07..c3b8a41eb9 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -2892,7 +2892,9 @@ declare namespace $derived { * https://svelte.dev/docs/svelte/$effect * @param fn The function to execute */ -declare function $effect(fn: (input: { signal: AbortSignal }) => void | ((input: { signal: AbortSignal }) => void)): void; +declare function $effect( + fn: (input: { signal: AbortSignal }) => void | (() => void) | Promise +): void; declare namespace $effect { /** @@ -2911,7 +2913,9 @@ declare namespace $effect { * https://svelte.dev/docs/svelte/$effect#$effect.pre * @param fn The function to execute */ - export function pre(fn: (input: { signal: AbortSignal }) => void | ((input: { signal: AbortSignal }) => void)): void; + export function pre( + fn: (input: { signal: AbortSignal }) => void | (() => void) | Promise + ): void; /** * The `$effect.tracking` rune is an advanced feature that tells you whether or not the code is running inside a tracking context, such as an effect or inside your template.