foxbenjaminfox/vue-async-computed

Typescript / vue-async-computed Property 'foo' does not exist on type 'CombinedVueInstance<Vue, {...}

DGollings opened this issue · 2 comments

Note that I don't use the vue/typescript class decoration style, so didn't have much luck with the examples in #25

No matter what I do, spent the entire afternoon on this because I really like vue-async-computed ;), I get the error Property 'foo' does not exist on type 'CombinedVueInstance.

'Annoyingly', everything works just fine, it's just an error.

console.log(this), I can see the computed property there. Can interact with it, recompute, etc.. Like I said, things work.

Installed using npm, using version 3.8.2, initialized centrally using

import AsyncComputed from "vue-async-computed";
Vue.use(AsyncComputed)

(possibly relevant, I also import import "regenerator-runtime/runtime")

used in a .vue file like this:
(note: adding default or lazy:true changed nothing)

asyncComputed: {
    async foo(): Promise<something> {
      try {
        return Promise.resolve("bar");
      } catch (err) {
            return Promise.reject(err);
      }
    },
  },

The whole async/try/catch is the reason for importing regenerator-runtime/runtime. Removing async and just returning "bar" doesnt help.

And any reference to this.foo elsewhere results in that error, again, it'll work, but with an error.

For now I've added

      // @ts-ignore
      // prettier-ignore

but would

I've been able to 'break' the typescript support, resulting in an error that 'asyncComputed' itself is unknown when it comes the Vue object. So something is working.

Any idea what could be the cause?

doits commented

I think there is no automatic solution. You can duplicate the definitions like this #25 (comment) though, then it will be picked up.

I think this should be possible. It has been done with mixins before
https://github.com/ktsn/vue-typed-mixins/blob/master/src/index.ts