From 561ed8f3d955460853d72cf070cdaf23691217a0 Mon Sep 17 00:00:00 2001 From: Jayden Carey Date: Thu, 23 Jan 2025 13:11:21 +0800 Subject: [PATCH] update type --- packages/svelte/elements.d.ts | 4 +++- packages/svelte/src/attachments/public.d.ts | 7 ++++++- .../phases/3-transform/client/visitors/shared/component.js | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/svelte/elements.d.ts b/packages/svelte/elements.d.ts index 7b67e2a07ebd..cb1df6ddebab 100644 --- a/packages/svelte/elements.d.ts +++ b/packages/svelte/elements.d.ts @@ -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'; @@ -861,7 +863,7 @@ export interface HTMLAttributes 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 & {}); diff --git a/packages/svelte/src/attachments/public.d.ts b/packages/svelte/src/attachments/public.d.ts index 7685151ab4b1..fe3811816b1c 100644 --- a/packages/svelte/src/attachments/public.d.ts +++ b/packages/svelte/src/attachments/public.d.ts @@ -1,4 +1,9 @@ +declare const brand: unique symbol; +type Brand = { [brand]: B }; +type Branded = T & Brand; +type AttachmentsKeySymbol = Branded; + /** * 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; diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js index 47b7b4436878..9621f29f7585 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js @@ -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) ),