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 #1248

Closed
bkp7 opened this issue Feb 11, 2021 · 1 comment · Fixed by #1249
Closed

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

bkp7 opened this issue Feb 11, 2021 · 1 comment · Fixed by #1249

Comments

@bkp7
Copy link
Contributor

bkp7 commented Feb 11, 2021

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

@bkp7
Copy link
Contributor Author

bkp7 commented Feb 24, 2021

In addition to the above a number of event emitter typescript definitions are missing or generically described. Missing ones are: disconnect, close, end, reconnect, offline, outgoingEmpty.
Generically described are: connect and message.
PR #1249 address all the TypeScript issues in this comment and above.

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