0

对于带有 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

我应该怎么做才能访问声明的模块的类型?

4

1 回答 1

1

我通过将类型与接口分开来解决它。谢谢@sno2!

export type TableTypes = {
        // base tables
        groups: Knex.CompositeTableType<
            // Table
            typeof GroupDB.type,
            // Insert
            typeof GroupDBInsert.type,
            // Update
            typeof GroupDBUpdate.type
        >;
    };

declare module "knex/types/tables" {
    // eslint-disable-next-line @typescript-eslint/no-empty-interface
    interface Tables extends TableTypes {}
}
于 2022-01-09T22:40:50.677 回答