打字稿:假装 foo 不在类型栏中,而它是:如何调试

问题描述 投票:0回答:1

当我做

tx.idbtrans
时,我有一个错误:

Error: Property 'idbtrans' does not exist on type 'Transaction & { fileInfo: EntityTable<FileInfo, "id">; }'. 
        await db.transaction("rw", x.myUndoTransactionsToApply.tables.flat(), async (tx) => {
          wmNormalUndoOrRedo.set(tx.idbtrans, 2); // 2 means we are in a redo operation
          if(x && x.myUndoTransactionsToApply) 

但是如果我检查交易类型(在文档中或在源代码中,因为我使用npm链接),我可以看到

idbtrans
DOES存在:

$ cat src/classes/transaction/transaction.ts
…
/** Transaction
 * 
 * https://dexie.org/docs/Transaction/Transaction
 * 
 **/
export class Transaction implements ITransaction {
…
  idbtrans: IDBTransaction;
…

知道如何调试吗?例如,我可以打印

Transaction
的完整描述来查看事务中应该允许哪些属性吗?

typescript indexeddb
1个回答
0
投票

如果你在Dexie github上查看源代码,

idbtrans
不存在。

idbtrans
存在于
Transaction
中的最后一个版本是7年前。我认为他们要么忘记更新文档,要么搞乱了 d.ts 而没有意识到。

您可以尝试手动编辑本地

node_modules/dexie/dist/dexie.d.ts
以将其添加回来,看看这是否适合您。正如您所说,按照
transaction.ts
的建议,它可能仍然存在于班级中。

export interface Transaction {
    db: Dexie;
    active: boolean;
    mode: IDBTransactionMode;
    idbtrans: IDBTransaction; //Add this line
    //tables: { [type: string]: Table<any, any> }; Deprecated since 2.0. Obsolete from v3.0.
    storeNames: Array<string>;
    explicit?: boolean;
    parent?: Transaction;
    on: TransactionEvents;
    abort(): void;
    table(tableName: string): Table<any, any>;
    table<T>(tableName: string): Table<T, any>;
    table<T, Key>(tableName: string): Table<T, Key>;
}
© www.soinside.com 2019 - 2024. All rights reserved.