```js // @noErrors import { createAttachmentKey, fromAction } from 'svelte/attachments'; ``` ## createAttachmentKey
Available since 5.29
Creates an object key that will be recognised as an attachment when the object is spread onto an element, as a programmatic alternative to using `{@attach ...}`. This can be useful for library authors, though is generally not needed when building an app. ```svelte ```
```dts function createAttachmentKey(): symbol; ```
## fromAction
```dts function fromAction< Node extends HTMLElement, Parameter extends any >( ...args: undefined extends NoInfer ? [ action: ( node: Node, parameter?: never ) => void | ActionReturn< Parameter, Record >, parameter?: (() => NoInfer) | undefined ] : [ action: ( node: Node, parameter: Parameter ) => void | ActionReturn< Parameter, Record >, parameter: () => NoInfer ] ): Attachment; ```
## Attachment An [attachment](/docs/svelte/@attach) is a function that runs when an element is mounted to the DOM, and optionally returns a function that is called when the element is later removed. It can be attached to an element with an `{@attach ...}` tag, or by spreading an object containing a property created with [`createAttachmentKey`](/docs/svelte/svelte-attachments#createAttachmentKey).
```dts interface Attachment {/*…*/} ```
```dts (element: T): void | (() => void); ```
## FromAction
```dts interface FromAction< Element extends EventTarget = HTMLElement, Par = unknown > {/*…*/} ```
```dts ( ...args: undefined extends NoInfer ? [ action: (node: Node, parameter?: never) => void | ActionReturn, parameter?: () => NoInfer ] : [ action: (node: Node, parameter: Parameter) => void | ActionReturn, parameter: () => NoInfer ] ): Attachment; ```