Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c3a0407

Browse files
authoredJul 27, 2024··
docs: add typing global custom directives
1 parent 0408888 commit c3a0407

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
 

‎src/guide/reusability/custom-directives.md

+23
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,26 @@ When used on components, custom directives will always apply to a component's ro
230230
```
231231

232232
Note that components can potentially have more than one root node. When applied to a multi-root component, a directive will be ignored and a warning will be thrown. Unlike attributes, directives can't be passed to a different element with `v-bind="$attrs"`.
233+
234+
235+
## Typing Global Custom Directives {#typing-global-custom-directives}
236+
237+
In order to get autocompletion and type-checking for your global custom directives, you can extend the `ComponentCustomProperties` interface.
238+
239+
```ts
240+
import { type Directive } from "vue"
241+
242+
declare module "vue" {
243+
interface ComponentCustomProperties {
244+
vCustomDirective: Directive<unknown, {foo: "value1" | "value2"}>
245+
}
246+
}
247+
```
248+
249+
```vue-html
250+
<!-- template of MyComponent -->
251+
252+
<div v-custom-directive="{ foo: 'value1' }"> <!-- autocompletion + type-check -->
253+
<span>My component content</span>
254+
</div>
255+
```

0 commit comments

Comments
 (0)
Please sign in to comment.