From 7303f2fdc7d3457ce957e5901992f452b84877e4 Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Mon, 7 Mar 2022 18:41:12 +0100 Subject: [PATCH] add `Action` type --- src/runtime/index.ts | 1 + src/runtime/internal/dom.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/runtime/index.ts b/src/runtime/index.ts index 8e12f9f0ee..fa45e190af 100644 --- a/src/runtime/index.ts +++ b/src/runtime/index.ts @@ -11,6 +11,7 @@ export { hasContext, tick, createEventDispatcher, + Action, SvelteComponentDev as SvelteComponent, SvelteComponentTyped } from 'svelte/internal'; diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 287c16b5fc..641d6ae35d 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -732,3 +732,20 @@ export function get_custom_elements_slots(element: HTMLElement) { }); return result; } + + +type ActionWithParams = ( + node: Node, + options: Params +) => { + update?: (params: Params) => void + destroy?: () => void +} + +type ActionWithoutParams = (node: Node) => { + destroy?: () => void +} + +export type Action = void extends Params + ? ActionWithoutParams + : ActionWithParams