8000 overload · sveltejs/svelte@7c2a49e · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c2a49e

Browse files
committed
overload
1 parent d166cd6 commit 7c2a49e

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

packages/svelte/src/attachments/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ export function createAttachmentKey() {
3131
return Symbol(ATTACHMENT_KEY);
3232
}
3333

34+
/**
35+
* @template {EventTarget} E
36+
* @template {unknown} T
37+
* @overload
38+
* @param {Action<E, T> | function(E, T): void | ActionReturn<T>} action The action function
39+
* @param {() => T} fn A function that returns the argument for the action
40+
* @returns {Attachment<E>}
41+
*/
42+
/**
43+
* @template {EventTarget} E
44+
* @overload
45+
* @param {Action<E, void> | function(E): void | ActionReturn<void>} action The action function
46+
* @returns {Attachment<E>}
47+
*/
3448
/**
3549
* Converts an Action into an Attachment keeping the same behavior. It's useful if you want to start using
3650
* attachments on Components but you have library provided actions.
@@ -41,7 +55,7 @@ export function createAttachmentKey() {
4155
* @template {EventTarget} E
4256
* @template {unknown} T
4357
* @param {Action<E, T> | function(E, T): void | ActionReturn<T>} action The action function
44-
* @param {() => T} [fn] A function that returns the argument for the action
58+
* @param {() => T} fn A function that returns the argument for the action
4559
* @returns {Attachment<E>}
4660
* @since 5.32
4761
*/

packages/svelte/types/index.d.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -659,18 +659,10 @@ declare module 'svelte/attachments' {
659659
* @since 5.29
660660
*/
661661
export function createAttachmentKey(): symbol;
662-
/**
663-
* Converts an Action into an Attachment keeping the same behavior. It's useful if you want to start using
664-
* attachments on Components but you have library provided actions.
665-
*
666-
* Note that the second argument, if provided, must be a function that _returns_ the argument to the
667-
* action function, not the argument itself.
668-
*
669-
* @param action The action function
670-
* @param fn A function that returns the argument for the action
671-
* @since 5.32
672-
*/
673-
export function fromAction<E extends EventTarget, T extends unknown>(action: Action<E, T> | ((arg0: E, arg1: T) => void | ActionReturn<T>), fn?: (() => T) | undefined): Attachment<E>;
662+
663+
export function fromAction<E extends EventTarget, T extends unknown>(action: Action<E, T> | ((arg0: E, arg1: T) => void | ActionReturn<T>), fn: () => T): Attachment<E>;
664+
665+
export function fromAction<E extends EventTarget>(action: Action<E, void> | ((arg0: E) => void | ActionReturn<void>)): Attachment<E>;
674666

675667
export {};
676668
}

0 commit comments

Comments
 (0)
0