Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property 'material' does not exist on type 'typeof Vue'. #736

Closed
mjknight50 opened this issue May 9, 2017 · 8 comments
Closed

Property 'material' does not exist on type 'typeof Vue'. #736

mjknight50 opened this issue May 9, 2017 · 8 comments

Comments

@mjknight50
Copy link

mjknight50 commented May 9, 2017

Perhaps this is related to #662, but when I try to use Vue Material in my boot.ts, I get this:

TS2339: Property 'material' does not exist on type 'typeof Vue'.

import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);

var VueMaterial = require('vue-material')
Vue.use(VueMaterial)


const routes = [
    { path: '/', component: require('./components/home/home.vue.html') },
    { path: '/inventory', component: require('./components/inventory/inventory.vue.html') },
];

Vue.material.registerTheme('default', {
    primary: {
        color: 'indigo',
        hue: 'A200'
    },
    accent: {
        color: 'grey',
        hue: 300
    }
})

new Vue({
    el: '#app-root',
    router: new VueRouter({ mode: 'history', routes: routes }),
    render: h => h(require('./components/app/app.vue.html'))

});
@d3radicated
Copy link

Maybe because of require? Try using import for vue-material.

import Vue from 'vue';
import VueMaterial from 'vue-material';
import VueRouter from 'vue-router';

Vue.use(VueMaterial);
Vue.use(VueRouter);

@mjknight50
Copy link
Author

That is a good suggestion, but I had tried that with no luck.

If I change from typescript to javascript, everything works fine, but that isn't really a solution.

@Morgul
Copy link
Member

Morgul commented May 11, 2017

@mjknight50 You correctly identified that this is related to #662. The problem comes in that we need a TypeScript language changes in order to support this. Currently, you cannot extend a class definition in another type definition file:

So, this means that Vue.material.registerTheme will never work inside of typescript at the moment. That is (currently) a fundamental limitation of Typescript definition files.

I'm not a TypeScript expert by any means, but at the moment, I believe your options are limited. The first would be to put your VueMaterial registration into a separate initVueMaterial.js file, and then call that from your TypeScript.

A second options would be to declare your own Vue type that inherits from the base Vue type, and adds .material, and then case Vue to that inside your app.ts. Frankly, I'm not sure if that would work correctly or not, but some reading around seems to suggest it might.

@mjknight50
Copy link
Author

@Morgul Thanks for your time in responding...
The easiest work-around for me was to just change my boot.ts to a JS file, leaving in place all the rest of my typescript.

@MichaelFedora
Copy link

@mjknight50 due note that while it errors it's just a type error; it will still compile. If you want to "ignore" it, you can do (Vue as any).material.registerTheme(/* ... */);.

It would be beneficial if Vue changed their class definition to an interface so that it could be extended, but oh well.

@elbow-jason
Copy link

my workaround (it's a hack, but it works):

let VuePatch: any = Vue

VuePatch.use(VueMaterial)

VuePatch.material.registerTheme('default', {
  primary: 'blue',
  accent: 'red',
  warn: 'red',
  background: 'grey'
})

let appMain = new VuePatch({
  el: '#app-main',
  router,
  store,
})

Notice the instantiation of the app uses the VuePatch variable.

@Morgul
Copy link
Member

Morgul commented Jun 21, 2017

I'm going to close this, as any typescript support will be tracked in #622. 😄

@Morgul Morgul closed this as completed Jun 21, 2017
@MichaelFedora
Copy link

MichaelFedora commented Jun 22, 2017

@Morgul it seems you referenced the wrong issue 😉 #662 seems to be the right one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants