Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dirty-garlics-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

feat: add type of `$effect.active`
22 changes: 22 additions & 0 deletions packages/svelte/src/main/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ declare namespace $effect {
* @param fn The function to execute
*/
export function pre(fn: () => void | (() => void)): void;

/**
* The `$effect.active` rune is an advanced feature that tells you whether or not the code is running inside an effect or inside your template.
*
* Example:
* ```svelte
* <script>
* console.log('in component setup:', $effect.active()); // false
*
* $effect(() => {
* console.log('in effect:', $effect.active()); // true
* });
* </script>
*
* <p>in template: {$effect.active()}</p> <!-- true -->
* ```
*
* This allows you to (for example) add things like subscriptions without causing memory leaks, by putting them in child effects.
*
* https://svelte-5-preview.vercel.app/docs/runes#$effect-active
*/
export function active(): boolean;
}

/**
Expand Down