-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I'm not a fan of RxJS and I sincerly have no clue where the error could come from. The only thing that comes to my mind is that we use a custom TypedEventEmitter implementation that may be the cause of your issues: https://github.com/mqttjs/MQTT.js/blob/main/src/lib/TypedEmitter.ts I kindly ask you to do some tests your own and open a PR to fix this if you find a solution |
Beta Was this translation helpful? Give feedback.
-
It looks like I don't see a clean way to fix this, other than overriding the return type: import { connect, IClientOptions, IPublishPacket, OnMessageCallback, Packet } from "mqtt";
import { fromEvent, type Observable } from "rxjs";
//...
const message$ = fromEvent(powerLinesMQTTClient, "message") as unknown as Observable<Parameters<OnMessageCallback>>; |
Beta Was this translation helpful? Give feedback.
It looks like
fromEvent
infers the type of event handler argument in a way that does not consider the actual event name, butMqttClient
has different handler signatures for each event.You end up with the arguments for the
packetsend
event, which is(packet: Packet)
, when you wanted the arguments for themessage
event, which is(topic: string, payload: Buffer, packet: IPublishPacket)
.I don't see a clean way to fix this, other than overriding the return type: