From 06b9b91528a75a620a77feea060995e29691012c Mon Sep 17 00:00:00 2001 From: David Fahlander Date: Fri, 24 May 2024 17:10:36 +0200 Subject: [PATCH] TInsertType in table() methods on Dexie and Transaction (#1998) * TInsertType in table() methods on Dexie and Transaction * Testing that typings of table-props works also on transactions. --- src/public/types/dexie.d.ts | 2 +- src/public/types/transaction.d.ts | 1 + test/typings-test/test-typings.ts | 22 +++++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/public/types/dexie.d.ts b/src/public/types/dexie.d.ts index 1f25a5172..67189f651 100644 --- a/src/public/types/dexie.d.ts +++ b/src/public/types/dexie.d.ts @@ -50,7 +50,7 @@ export interface Dexie { open(): PromiseExtended; - table(tableName: string): Table; + table(tableName: string): Table; transaction( mode: TransactionMode, diff --git a/src/public/types/transaction.d.ts b/src/public/types/transaction.d.ts index 8e170a521..d2f5eb9bb 100644 --- a/src/public/types/transaction.d.ts +++ b/src/public/types/transaction.d.ts @@ -16,4 +16,5 @@ export interface Transaction { table(tableName: string): Table; table(tableName: string): Table; table(tableName: string): Table; + table(tableName: string): Table; } diff --git a/test/typings-test/test-typings.ts b/test/typings-test/test-typings.ts index 795b0a056..cb05c9010 100644 --- a/test/typings-test/test-typings.ts +++ b/test/typings-test/test-typings.ts @@ -3,7 +3,7 @@ * It tests Dexie.d.ts. */ -import Dexie, { IndexableType, Table, replacePrefix } from '../../dist/dexie'; // Imports the source Dexie.d.ts file +import Dexie, { EntityTable, IndexableType, Table, replacePrefix } from '../../dist/dexie'; // Imports the source Dexie.d.ts file import './test-extend-dexie'; import './test-updatespec'; @@ -275,3 +275,23 @@ import './test-updatespec'; db.friends.where({name: 'Kalle'}).modify({name: replacePrefix('K', 'C')}); } + + +{ + // Typings for tables in both Dexie and Transaction + interface Friend { + id: number; + name: string; + age: number; + } + + const db = new Dexie('dbname') as Dexie & { + friends: EntityTable; + items: Table<{id: number, name: string}, number>; + } + + db.friends.add({name: "Foo", age: 22}); + db.transaction('rw', db.friends, tx => { + tx.friends.add({name: "Bar", age: 33}); + }) +}