【发布时间】:2022-01-09 22:17:42
【问题描述】:
对于带有typescript support 的 knexjs,我设置了以下内容:
declare module "knex/types/tables" {
interface Tables {
// base tables
groups: Knex.CompositeTableType<
// Table
typeof GroupDB.type,
// Insert
typeof GroupDBInsert.type,
// Update
typeof GroupDBUpdate.type
>;
}
}
它有效。我想重用接口中找到的类型。
import { Tables } from "knex/types/tables";
let tableName: keyof Tables = "groups"
但knex/types/tables 会因错误而失败
Unable to resolve path to module 'knex/types/tables'.eslintimport/no-unresolved
我应该怎么做才能访问声明的模块的类型?
【问题讨论】:
-
您是否已将
declare module部分放入声明 (d.ts) 文件中? -
@sno2 不。它在一个 .ts 文件中,但我会尝试。它在带有 knexjs 的 .ts 中正常工作并显示正确的表名。
-
@sno2 它仍然失败并出现同样的错误
-
太糟糕了,看起来您需要三斜杠引用。请参阅此处的文档typescriptlang.org/docs/handbook/modules.html#ambient-modules
-
您也可以在没有
declare module部分的情况下定期从文件(即knex.ts)导入/导出类型。
标签: typescript import module knexjs