vuejs/vue-rx

subscriptions in the Vue options makes using @VueClassComponent clumsy

awk opened this issue · 1 comments

awk commented

Since subscriptions is not declared in the Vue ComponentOptions interface adding it to the options when also using the @VueClassComponent decorator in Typescript causes the TS compiler to believe that the supplied parameter is an instance of VueClass (since it no longer fits the profile of a Vue ComponentOptions) - however the parameter really is an instance of ComponentOptions :-(

The only way I've found to avoid this is to use a set of casts on the argument to @VueClassComponent:

@VueClassComponent(<ComponentOptions<MyVueComponent>>{
  subscriptions: …
  props: …
})
export class MyVueComponent extends Vue {
…

If instead subscriptions was actually a method on the component (MyVueComponent) it would not be necessary to have a custom field added to ComponentOptions and the casts would not be necessary. I think the patch would be a few lines to look at vm.subscriptions if vm.$options.subscriptions were null/undefined. However I'm wondering if there's some reason why subscriptions must be part of the options that I'm missing?

awk commented

Actually - I found a work around by declaring an extension to Vue ComponentOptions:

import Vue = require('vue');

declare module 'vue/types/options' {
  interface ComponentOptions<V extends Vue> {
    subscriptions?: {[key: string]: Object} | Function;
  }
}