我需要在typescript下使用kafka节点:
const kafkaHost = 'localhost:9092';
const client = new Client({ kafkaHost });
启动index.ts后,出现以下错误:
Property '_write' in type 'ProducerStream' is not assignable to the same property in base type 'Writable'.
Type '(message: ProduceRequest, encoding: "utf8" | "buffer", cb: (error: any, data: any) => any) => void' is not assignable to type '(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null | undefined) => void) => void'.
Types of parameters 'encoding' and 'encoding' are incompatible.
Type 'BufferEncoding' is not assignable to type '"utf8" | "buffer"'.
Type '"ascii"' is not assignable to type '"utf8" | "buffer"'.
143 _write (message: ProduceRequest, encoding: 'buffer' | 'utf8', cb: (error: any, data: any) => any): void;
我认为问题是在类型,所以我没有安装 @types/kafka-node
尽管如此,它还是被弃用了。
如何修复?
1条答案
按热度按时间4c8rllxm1#
kafka节点现在为typescript提供了自己的预定义类型。你可以从这里介绍他们
关于您的问题,您需要在使用前导入正确的类型: