Vuefire: Can't use computed properties with TypeScript because of "Property '{prop_name}' does not exist on type 'Vue'." error

Created on 15 Sep 2018  路  6Comments  路  Source: vuejs/vuefire

Consider the following code snippet:

import { Component, Vue } from "vue-property-decorator";
import { db } from "../../modules/firebase-client/";
import { DocumentReference } from "firebase/firestore";

@Component({
  name: "SingleEntry",
  firestore() {
    return {
      entry: db.collection("dashboard-entries").doc(this.$route.params.id),
      queue: db.collection("tasks-queue").where("entryRef", "==", this.entryRef)
    };
  },
  validations
})
export default class SingleEntry extends Vue {
  get entryRef(): DocumentReference {
    return db.collection("dashboard-entries").doc(this.$route.params.id);
  }
}

the queue property uses a computed value that's returned by the entryRef computed property. The code works (I can see proper results of the query rendered on the template), but TypeScript compiler is complaining that:

ERROR in /Users/wujekbogdan/htdocs/sw-rss-dashboard/src/views/SingleEntry/SingleEntry.vue
210:72 Property 'entryRef' does not exist on type 'Vue'.
    208 |     return {
    209 |       entry: db.collection("dashboard-entries").doc(this.$route.params.id),
  > 210 |       queue: db.collection("tasks-queue").where("entryRef", "==", this.entryRef)
        |                                                                        ^
    211 |     };
    212 |   },
    213 |   validations

Am I doing something wrong or is it a problem caused by incomplete/buggy typings declarations?

firestore

Most helpful comment

Hi.

You need to write like this, for example

@Component<SingleEntry>({
  firestore() {
    this
  }
})
export default class SingleEntry extends Vue {}

All 6 comments

I really don't know, the type declaration file is here: https://github.com/vuejs/vuefire/blob/lerna/packages/vuefire/types/vue.d.ts#L33 and we did add the this

I really don't know, the type declaration file is here: https://github.com/vuejs/vuefire/blob/lerna/packages/vuefire/types/vue.d.ts#L33 and we did add the this

  • @posva maybe we need to add this link or make a tip in README file of this version? It should be helpful for many other typescript's guys I think

If it wasn't for your answer, I'd be looking for typings for this wrapper for a long time

But it should be automatic if it's added in the right field in the package json file, shouldn't it?

@posva When I googled something like "vuefire" I found the repo without types vuefire 1.4.5 it's installing like npm install vuefire but if i'd like to get types supporting in typescipt I have to get another version from here vuefire v. 2 alpha as npm i vuefire@next (it's working for me now).

Did I understand the best way to implement it now? In this case, we could mark it in readme file of stable version as a tip for typescript developers. Or alpha is very unstable now? Sorry for my bad English.

Hi.

You need to write like this, for example

@Component<SingleEntry>({
  firestore() {
    this
  }
})
export default class SingleEntry extends Vue {}

Closing as it seems to be resolved

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KMolendijk picture KMolendijk  路  3Comments

mkharibalaji picture mkharibalaji  路  3Comments

drumanagh picture drumanagh  路  3Comments

franciscolourenco picture franciscolourenco  路  7Comments

weavermedia picture weavermedia  路  4Comments