Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egronomic way to provide schema via JSDoc #303

Open
randName opened this issue Dec 5, 2023 · 0 comments
Open

egronomic way to provide schema via JSDoc #303

randName opened this issue Dec 5, 2023 · 0 comments

Comments

@randName
Copy link
Contributor

randName commented Dec 5, 2023

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

@@ -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™️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant