add `Action` type

pull/7347/head
Ivan Hofer 5 years ago
parent eb6fb66f19
commit 7303f2fdc7

@ -11,6 +11,7 @@ export {
hasContext, hasContext,
tick, tick,
createEventDispatcher, createEventDispatcher,
Action,
SvelteComponentDev as SvelteComponent, SvelteComponentDev as SvelteComponent,
SvelteComponentTyped SvelteComponentTyped
} from 'svelte/internal'; } from 'svelte/internal';

@ -732,3 +732,20 @@ export function get_custom_elements_slots(element: HTMLElement) {
}); });
return result; return result;
} }
type ActionWithParams<Node extends HTMLElement = HTMLElement, Params extends any = any> = (
node: Node,
options: Params
) => {
update?: (params: Params) => void
destroy?: () => void
}
type ActionWithoutParams<Node extends HTMLElement = HTMLElement> = (node: Node) => {
destroy?: () => void
}
export type Action<Node extends HTMLElement = HTMLElement, Params extends any = void> = void extends Params
? ActionWithoutParams<Node>
: ActionWithParams<Node, Params>

Loading…
Cancel
Save