From 3cb9dcf186cadbff248d8fc0ecb10f324b92ef01 Mon Sep 17 00:00:00 2001 From: tanhauhau Date: Mon, 11 Apr 2022 18:56:49 +0800 Subject: [PATCH] ActionReturn should return destroy only if Parameter is void Co-authored-by: Ivan Hofer --- src/runtime/action/index.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/runtime/action/index.ts b/src/runtime/action/index.ts index d7cbf04b12..3469ecbb71 100644 --- a/src/runtime/action/index.ts +++ b/src/runtime/action/index.ts @@ -17,10 +17,14 @@ * * Docs: https://svelte.dev/docs#template-syntax-element-directives-use-action */ -export interface ActionReturn { - update?: (parameter: Parameter) => void; - destroy?: () => void; -} +export type ActionReturn = void extends Parameter + ? { + destroy?: () => void; + } + : { + update?: (parameter: Parameter) => void; + destroy?: () => void; + } /** * Actions are functions that are called when an element is created. @@ -37,6 +41,7 @@ export interface ActionReturn { * * Docs: https://svelte.dev/docs#template-syntax-element-directives-use-action */ -export interface Action { - (node: Node, parameter?: Parameter): void | ActionReturn; -} +export type Action = + void extends Parameter + ? (node: Node) => void | ActionReturn + : (node: Node, parameter: Parameter) => void | ActionReturn;