jakearchibald / idb

IndexedDB, but with promises
https://www.npmjs.com/package/idb
ISC License
6.31k stars 356 forks source link

Issue with 4.0.5 #130

Closed DaveLomber closed 4 years ago

DaveLomber commented 4 years ago

After upgraded from 4.0.4 to 4.0.5 I started getting the following error:

ERROR in ../node_modules/idb/lib/async-iterators.ts:40:5 - error TS2322: Type 'IDBPCursorWithValue<unknown, string[], string, unknown> | IDBPCursorWithValue<unknown, string[], string, string>' is not assignable to type 'IDBPCursor<unknown, string[], string, unknown> | IDBPIndex<unknown, string[], string, string> | IDBPObjectStore<unknown, string[], string>'.
  Type 'IDBPCursorWithValue<unknown, string[], string, string>' is not assignable to type 'IDBPCursor<unknown, string[], string, unknown> | IDBPIndex<unknown, string[], string, string> | IDBPObjectStore<unknown, string[], string>'.
    Type 'IDBPCursorWithValue<unknown, string[], string, string>' is not assignable to type 'IDBPCursor<unknown, string[], string, unknown>'.
      Types of property 'source' are incompatible.
        Type 'IDBPIndex<unknown, string[], string, string>' is missing the following properties from type 'IDBPObjectStore<unknown, string[], string>': indexNames, transaction, add, clear, and 6 more.

40     cursor = await (cursor as IDBPObjectStore | IDBPIndex).openCursor(...args);
Txuso commented 4 years ago

Same here :-(

jakearchibald commented 4 years ago

Thanks for the report, I'll take a look

jakearchibald commented 4 years ago

@DaveLomber @Txuso can you give me some example code that triggers the above error?

I tried the following:

import { openDB, DBSchema } from 'idb/with-async-ittr';

interface MyDB extends DBSchema {
  'favourite-number': {
    key: string;
    value: number;
  };
  products: {
    value: {
      name: string;
      price: number;
      productCode: string;
    };
    key: string;
    indexes: { 'by-price': number };
  };
}

openDB<MyDB>('foo', 1).then(async db => {
  const tx = db.transaction('favourite-number');

  for await (const cursor of tx.store) {
    console.log(cursor);
  }
});

…and it worked without error.

I also tried it without types:

import { openDB } from 'idb/with-async-ittr';

openDB('foo', 1).then(async db => {
  const tx = db.transaction('favourite-number');

  for await (const cursor of tx.store) {
    console.log(cursor);
  }
});

…but again, no error. What am I missing?

smout74 commented 4 years ago

I can confirm this error with Ionic 4 + Angular

jakearchibald commented 4 years ago

I'm interested in fixing this, but can't without a reproducible test case. Please reopen this when you have one.

I'm unfamiliar with Ionic & Angular, so ideally can you give me a reduced project that only contains what's needed to recreate the issue.