【问题标题】:Adding Dexie.js queries in JavaScript file gives hint of missing type在 JavaScript 文件中添加 Dexie.js 查询会提示缺少类型
【发布时间】:2022-01-01 10:38:15
【问题描述】:

如果我在 JavaScript 文件中添加 Dexie.js 查询,例如:

let friends = liveQuery(async () => {
  return await db.friends
    .where("age")
    .between(18, 65)
    .toArray();
});

我得到这样的提示:

“'Dexie'.ts(2339) 类型上不存在属性'friends'”

为什么?

将它放在Svelte 文件中很好,但我想将一些基本查询保存在一个地方,例如查找、添加和删除。

【问题讨论】:

  • 为什么用 Visual Studio Code 标记?
  • 在 vscode 中。应该这么说。

标签: javascript visual-studio-code dexie


【解决方案1】:

我想您指的是 TypeScript 错误。如果您没有按照Dexie's Svelte tutorial 的建议对 Dexie 进行子类化,那么您不能直接使用 db.friends 而不会出现 TypeScript 抱怨。如果不想继承 Dexie,也可以使用table() 方法:

let friends = liveQuery(async () => {
  return await db.table('friends')
    .where("age")
    .between(18, 65)
    .toArray();
});

【讨论】:

    猜你喜欢
    • 2021-01-14
    • 2020-01-18
    • 2015-06-12
    • 1970-01-01
    • 2017-02-03
    • 1970-01-01
    • 2018-03-16
    • 2018-03-07
    • 2015-08-10
    相关资源
    最近更新 更多