Typescript的新功能。我正在从RabbitMQ通道读取一些数据,并将其转换为JSON对象。在这一行我得到了错误
让communicationInformation = JSON.parse(newCommunication.content);
TS2345:“缓冲区”类型的参数无法分配给“字符串”类型的参数。
我需要投射数据吗?我正在使用Typescript 2.4.1
Amqplib.connect(amqpLibUrl, (err, connection) => {
if (!err) {
connection.createChannel((err, channel) => {
channel.consume('QueueName', newCommunication => {
if (newCommunication != null) {
let communicationInformation = JSON.parse(newCommunication.content);
// Code
}
})
})
}
});
我认为该错误引发了的输入参数JSON.parse
。尝试先调用toString
它,然后传递给函数。
let communicationInformation = JSON.parse(newCommunication.content.toString());
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句