Skip to content

Commit 339ce84

Browse files
committed
tweak types
1 parent 999a05a commit 339ce84

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

packages/svelte/elements.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
3232
// TypeScript Version: 2.8
3333

34+
import type { Attachment } from 'svelte/attachments';
35+
3436
// Note: We also allow `null` as a valid value because Svelte treats this the same as `undefined`
3537

3638
type Booleanish = boolean | 'true' | 'false';
@@ -862,7 +864,7 @@ export interface HTMLAttributes<T extends EventTarget> extends AriaAttributes, D
862864
[key: `data-${string}`]: any;
863865

864866
// allow any attachment
865-
[key: symbol]: (node: T) => void | (() => void);
867+
[key: symbol]: Attachment<T>;
866868
}
867869

868870
export type HTMLAttributeAnchorTarget = '_self' | '_blank' | '_parent' | '_top' | (string & {});

packages/svelte/src/attachments/public.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* It can be attached to an element with an `{@attach ...}` tag, or by spreading an object containing
66
* a property created with [`createAttachmentKey`](https://svelte.dev/docs/svelte/svelte-attachments#createAttachmentKey).
77
*/
8-
export interface Attachment {
9-
(element: Element): void | (() => void);
8+
export interface Attachment<T extends EventTarget = Element> {
9+
(element: T): void | (() => void);
1010
}
1111

1212
export * from './index.js';

packages/svelte/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,8 @@ declare module 'svelte/attachments' {
632632
* It can be attached to an element with an `{@attach ...}` tag, or by spreading an object containing
633633
* a property created with [`createAttachmentKey`](https://svelte.dev/docs/svelte/svelte-attachments#createAttachmentKey).
634634
*/
635-
export interface Attachment {
636-
(element: Element): void | (() => void);
635+
export interface Attachment<T extends EventTarget = Element> {
636+
(element: T): void | (() => void);
637637
}
638638
/**
639639
* Creates an object key that will be recognised as an attachment when the object is spread onto an element,

0 commit comments

Comments
 (0)