-
Notifications
You must be signed in to change notification settings - Fork 356
-
Notifications
You must be signed in to change notification settings - Fork 356
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
IDBPTransaction TxStores type checking support #288
Comments
This can be achieved with generics. function add<S extends StoreNames<Schema>>(
tx: IDBPTransaction<Schema, ('foo' | S)[], 'readwrite'>
) {
const foo = tx.objectStore('foo');
// ...
} The |
Oh, thanks @indianakernick. Turns out And there I sat, thinking I know a lot about TS type-wizardry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
The transaction object returned by
db.transation(['foo', 'bar', 'baz'], 'readwrite')
has the typeIDBPTransaction<MyDb, ('foo' | 'bar' | 'baz')[], 'readwrite'>
I would like to pass this transaction object to a function that accepts transactions that can manage the store
'foo'
. Is this possible to check statically with TypeScript or do I have to use runtime checking?In #200 there's an example that uses tuples:
But this does not work:
Type '["foo"]' does not satisfy the constraint 'ArrayLike<"foo" | "bar" | "baz">'.
Describe the solution you'd like
It would be nice if something like this would work, but I can't figure out if it's currently possible:
The text was updated successfully, but these errors were encountered: