Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current Typescript definitions are difficult to use to read userProperties #102

Closed
bkp7 opened this issue Feb 11, 2021 · 0 comments · Fixed by #103
Closed

Current Typescript definitions are difficult to use to read userProperties #102

bkp7 opened this issue Feb 11, 2021 · 0 comments · Fixed by #103

Comments

@bkp7
Copy link
Contributor

bkp7 commented Feb 11, 2021

Using TypeScript, reading user properties requires something like this (MQTT client):

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 were changed from being {object} to being {[index: string]: string}.

It would also be better if the on message callback (in MQTT) 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.js#1248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant