jakearchibald / idb

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

Typescript Schema typing error #273

Closed peterwiebe closed 2 years ago

peterwiebe commented 2 years ago

I am just starting to use idb and am trying to follow the example in the Readme but I seem to be having a Typescript issue with the schema definition as defined:

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

interface MyDB extends DBSchema {
  items: {
    key: string;
    name: string;
  };
}

I get the following error message: Property 'items' of type '{ key: string; name: string; }' is not assignable to 'string' index type 'DBSchemaValue'.

dependencies: "idb": "^7.0.2", "typescript": "~4.5.2"

jakearchibald commented 2 years ago

name shouldn't be there https://github.com/jakearchibald/idb#typescript.

Can you show me the type of object you're wanting to store, and what its key is?

jakearchibald commented 2 years ago

Maybe you mean this?

interface MyDBFixed extends DBSchema {
  items: {
    key: string;
    value: { name: string };
  };
}
peterwiebe commented 2 years ago

My apologies, you are correct. I think I was rushing to try and grok the API and overlooked the format required for the type definition. Thank you for responding 🙏