Closed
Description
Using TypeScript, reading user properties requires something like this:
client.on('message', function(topic, message, packet) {
const pckt: IPublishPacket = Object.assign(packet);
if (pckt.properties && pckt.properties.userProperties) {
const userProperties: {[index: string]: string} = Object.assign(pckt.properties.userProperties);
console.log(userProperties['test']);
}
});
It would be better if the userProperties (in mqtt-packet) were changed from being {object} to being {[index: string]: string}.
It would also be better if the on message callback required an IPublishPacket rather than the more generic Packet.
Changing both these would allow type assignments to be removed and the TypeScript code could be changed to:
client.on('message', function(topic, message, packet) {
if (packet.properties && packet.properties.userProperties) {
console.log(packet.properties.userProperties['test']);
}
});
Linked to mqttjs/mqtt-packet#102
AB#9320335
Metadata
Metadata
Assignees
Labels
No labels