Skip to content

Commit

Permalink
update type
Browse files Browse the repository at this point in the history
  • Loading branch information
Not-Jayden committed Jan 23, 2025
1 parent 51c540c commit 561ed8f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/svelte/elements.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8

import { AttachmentsKey } from 'svelte/attachments';

// Note: We also allow `null` as a valid value because Svelte treats this the same as `undefined`

type Booleanish = boolean | 'true' | 'false';
Expand Down Expand Up @@ -861,7 +863,7 @@ export interface HTMLAttributes<T extends EventTarget> extends AriaAttributes, D
[key: `data-${string}`]: any;

// allow any attachment
[key: symbol]: (node: T) => void | (() => void);
[AttachmentsKey]: Array<(node: T) => void | (() => void)>;
}

export type HTMLAttributeAnchorTarget = '_self' | '_blank' | '_parent' | '_top' | (string & {});
Expand Down
7 changes: 6 additions & 1 deletion packages/svelte/src/attachments/public.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
declare const brand: unique symbol;
type Brand<B> = { [brand]: B };
type Branded<T, B> = T & Brand<B>;
type AttachmentsKeySymbol = Branded<symbol, 'svelte.attachments'>;

/**
* A unique symbol used for defining the attachments to be applied to an element or component.
*/
export const AttachmentsKey: unique symbol;
export const AttachmentsKey: AttachmentsKeySymbol;
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export function build_component(node, component_name, context, anchor = context.
push_prop(
b.prop(
'get',
b.call('Symbol'),
b.call("Symbol.for('svelte.attachments')"),
/** @type {Expression} */ (
context.visit(attachment.type === 'SpreadElement' ? attachment.argument : attachment)
),
Expand Down

0 comments on commit 561ed8f

Please sign in to comment.