Open randName opened 7 months ago
this is more of a personal itch, but as i'm mostly using types via JSDoc there is a small bit of friction when opening the db since there isn't a way to provide generics yet
/** @type {import('idb').IDBPDatabase<import('./schema').MySchema>} */ const db = await openDB('my-database', 1, { /* ... */ })
my suggestion would be to provide a prop that would allow openDB to infer the schema
openDB
@@ -53,6 +53,10 @@ export interface OpenDBCallbacks<DBTypes extends DBSchema | unknown> { + /** + * Convenience property for providing the database schema when using JSDoc. + */ + schema?: DBTypes; }
so the example above would look like
const db = await openDB('my-database', 1, { schema: /** @type {import('./schema').MySchema} */({}), /* ... */ })
No runtime code should be affected, but I am unsure if that is a good idea in the first place so feel free to dismiss this if you think it isn't. The workaround isn't too bad and TypeScript might fix it someday™️
this is more of a personal itch, but as i'm mostly using types via JSDoc there is a small bit of friction when opening the db since there isn't a way to provide generics yet
my suggestion would be to provide a prop that would allow
openDB
to infer the schemaso the example above would look like
No runtime code should be affected, but I am unsure if that is a good idea in the first place so feel free to dismiss this if you think it isn't. The workaround isn't too bad and TypeScript might fix it someday™️