[Vuejs]-Vue 3 custom directive with modifier type check

1👍

I don’t think it’s possible using a modifier, however you can do something similar with a directive value:

import type { ObjectDirective } from "vue";

type PossibleParams = "foo" | "bar";

const vTypedDirective: ObjectDirective<any, PossibleParams> = {
  mounted: (el: any) => el.focus(),
};


<div v-typed-directive="'bar'" /> // OK
<div v-typed-directive="'baz'" /> // TS error

Leave a comment