Skip to content

rabbitmq文件ts检查无法通过 #95

Description

@tree-lock

项目未做任何修改,

运行环境

yarn

docker-compose up -d
# 修改数据库的操作做了,这里忽略不写

yarn dev

然后就报错了。

如下第四行所示

  // src/app/service/rabbitmq.ts > RabbitmqService > connect
  async connect() {
    // 创建连接
    // @ts-ignore 这一行必须添加忽略注释才能通过
    this.connection = await amqp.connect(this.rabbitmq.url);

    // 创建 channel
    this.channel = await this.connection.createChannel();

    // 绑定队列
    await this.channel.assertQueue('my-queue', {
      exclusive: true,
      autoDelete: true,
    });
    // 绑定交换机
    await this.channel.bindQueue('my-queue', 'my-exchange', 'create');

    return this.connection;
  }

错误提示

[ Midway ] start error: ⨯ Unable to compile TypeScript:
src/app/service/rabbitmq.ts(29,5): error TS2740: Type 'IAmqpConnectionManager' is missing the following properties from type 'Connection': createConfirmChannel, off, removeAllListeners, setMaxListeners, and 6 more.

我对rabbitmq使用不多,也不知道这是个什么情况,但项目刚运行就报错。使用是docker安装的环境,忽略类型检查之后就能正常通过。

看了一些type类型定义,确实接口是对不上的,但amqp里有一个 connection 的 getter ,类型是 connection 所以能对上,但是它是 undefined 。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions