Vue JS materal design with TypeScript

716 Views Asked by At

I'm trying to use Vue JS material design with TypeScript, but it's not supported out of the box. Following this GitHub issue I've been trying to add declare a custom module, but without success. My app is created with vue create my-app command

I created a new file in src: types/vue-material/index.d.ts:

declare module 'vue-material' {
    import _Vue from "vue";
    
    export function MdButton(Vue: typeof _Vue, options?: any): void
    export function MdContent(Vue: typeof _Vue, options?: any): void
    export function MdTabs(Vue: typeof _Vue, options?: any): void
}

I added type roots and excluded the folder from tsconfig:

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

But still I'm getting an error when trying to import VueMaterial:

import { MdButton } from 'vue-material';
Could not find a declaration file for module 'vue-material'. 'C:/.../my-app/node_modules/vue-material/dist/vue-material.js' implicitly has an 'any' type.
  Try `npm install @types/vue-material` if it exists or add a new declaration (.d.ts) file containing `declare module 'vue-material';`

What I'm doing wrong?

0

There are 0 best solutions below