Add property to Vue Typescript

Asked

Viewed 32 times

0

I cannot compile my application because it is returning me the following error:

A propriedade '$acl' não existe no tipo 'Vue'. ts(2339)

Click to see the error image

If this is a scroll access control library, the point is that I’m trying to export a mixin and create a directive using my library, apparently it should all work early, but I can’t compile due to this error. I wanted to know how to customize the properties of Vuejs types, I already tried to create the @types/Vue.d.ts folder with the contents:

interface AclBody {
 change: Function;
 check: Function;
}

declare namespace Vue {
 export interface Vue {
  $acl: AclBody;
 }
}

and set up tsconfig.json:

{
 "compilerOptions": {
    ...
    "typeRoots": ["./src/@types", "./node_modules/@types"]
  }
}

I also tried to assign direct props in mixin:

 return Vue.extend({
   props: {
      $acl: {}
   }
 })

Unsuccessfully, I’d like a little help.

  • Thinking you only need to use the statement like this: declare namespace Vue { Let $Acl: any } I believe it works, I couldn’t test here to validate

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.