dexie / Dexie.js

A Minimalistic Wrapper for IndexedDB
https://dexie.org
Apache License 2.0
11.58k stars 642 forks source link

Unable to work with Dexie, Vue 3 and TypeScript #1461

Open nicojmb opened 2 years ago

nicojmb commented 2 years ago

Hi,

I tried to use Dexie with Vue 3 and typescript, but get error with "UseObservable" method:

image

image

image

Im' trying to find examples but not finded :(

dfahlander commented 2 years ago

The typing of useObservable had become incompatible but the runtime is correct.

The typings used to work with rxjs@6 but not rxjs@7. After adjusting typings for rxjs@7 it works less good for rxjs@6. This will work better when vueuse upgrades to rxjs@7. Until then, it seems you need an explicit cast:

useObservable (liveQuery (...) as any)
mattbisme commented 2 years ago

I've run into this same problem. However, the only explicit cast I can get to work is any. In the friends example above (or my customers below), is there a cast other than any that would work?

Additionally, I find that I also need to explicitly typecast useObservable with Ref, or it causes problems when I want to reference this.customers (in my example).


data() {
  return {
    authorized: false,
    sectionName: "RepairTagger",
    customers: useObservable(
      liveQuery(() => db.customers.toArray()) as any
    ) as Ref<Customer[]>,
    customerQuery: {
      limit: 20,
      sort: ['first_name'] as Array<keyof Customer>
    }
  }
},
Zyles commented 1 year ago

Yeah the vue demo does not work.

First of all I need to add lang="ts" to Githubissues.

  • Githubissues is a development platform for aggregating issues.