不可分配给 Knex 类型

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

我是个新手,不知道怎么做,Knex有两个变量名,我应该如何获取返回我想要的变量的方法。

import {knex, Knex} from 'knex';

public async createConnection(): Promise<Knex> {
  const config: Knex.Config = {
    client: 'mysql',
    connection: {
      host: this.config.host,
      port: this.config.port,
      user: this.config.user,
      password: this.config.password,
      database: this.config.database
    },
    debug: this.config.debug,
    migrations: {
      tableName: 'migrations'
    }
  };

  const db = knex(config);
  await db.raw('select 1');

  return db;
};

上面的代码webstorm报错了

TS2322:类型“Knex”不可分配给类型 'Knex[]>'。
返回的类型 'select().first().stream(...)' 之间不兼容 类型。
类型“PassThrough & AsyncIterable”不是 可分配给类型“PassThrough & AsyncIterable”。
类型 “PassThrough & AsyncIterable”不可分配给类型 'AsyncIterable'。
返回的类型 '[Symbol.asyncIterator]().next(...)' 在这些之间不兼容 类型。
类型“Promise>”不可分配 输入“Promise>”。
输入 “IteratorResult”不可分配给类型 'IteratorResult'。
类型'IteratorYieldResult'是 不可分配给类型“IteratorResult”。
类型 “IteratorYieldResult”不可分配给类型 “IteratorYieldResult”。
类型“any”不可分配给类型 '绝不'。
mysql node.js typescript webstorm knex.js
1个回答
0
投票
 public async createConnection(): Promise<Knex> {
        const config: Knex.Config = {
            client: 'mysql',
            connection: {
                host: this.config.host,
                port: this.config.port,
                user: this.config.user,
                password: this.config.password,
                database: this.config.database
            },
            debug: this.config.debug,
            migrations: {
                tableName: 'migrations'
            }
        }
        const db: Knex = knex(config)

        await db.raw('select 1');

        return db;
  
    }
© www.soinside.com 2019 - 2024. All rights reserved.