Skip to content

[Question] Support for typed custom Directives #554

Open
@Maxim-Mazurok

Description

@Maxim-Mazurok

🧐 Problem Description

As mentioned here, I'd like to have type safety for custom directives when using Vue 3 and JSX + Typescript (TSX).

💻 Sample code

import { defineCustomElement } from "vue";
import ClickOutside from "click-outside-vue3";

export default defineCustomElement({
  name: "Hello",
  directives: {
    clickOutside: ClickOutside.directive,
  },
  render() {
    return <div vClickOutside={() => console.log("clicked outside")}></div>;
  },
});

🚑 Other information

It works, but gives an annoying type error, saying:

Type '{ vClickOutside: () => void; }' is not assignable to type 'ElementAttrs<HTMLAttributes>'.
  Property 'vClickOutside' does not exist on type 'ElementAttrs<HTMLAttributes>'.ts(2322)

The current workaround that I applied is to use @ts-ignore (not that vite won't build it otherwise, but just to make the red line go away in VS Code), I didn't have time to figure out which interface I have to augment, potentially even patching node_modules using patch-package

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions