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

[question] Difficulties using with typescript #683

Closed
DrakoPOD opened this issue Nov 19, 2021 · 2 comments
Closed

[question] Difficulties using with typescript #683

DrakoPOD opened this issue Nov 19, 2021 · 2 comments
Labels

Comments

@DrakoPOD
Copy link

DrakoPOD commented Nov 19, 2021

I have this code, that works perfectly in vanilla JS:

aedes.on('publish', function (packet, client) {
	//More code...
	aedes.publish({
		topic: 'auth/' + client.id,
		payload: '1',
		qos: 0
	});
});

But with typescript it says that is missing one argument, in that case is callback, Then, I put the callback, but get another error that says (translate from Spanish):

Cannot assign an arg of type "{ topic: string; payload: string; qos: 0; }" to param of type "PublishPacket".
to type "{ topic: string; payload: string; qos: 0; }" is missing the following properties of type "IPublishPacket": cmd, dup, retain

It suppose that these properties should be defaults or optional, also the docs doesn't offer explanation of what properties have or what is PublishPacket. I know that properties are standard of mqtt, but at least a external link or something.

Also, I got another error with aedes.authenticate
'authenticate' does not exist on type 'aedes'

The code can run, at least I don't use typescript. Adding // @ts-expect-error ignore the problem. But, how I can import the type definitions?

@robertsLando
Copy link
Member

robertsLando commented Nov 21, 2021

@DrakoPOD you can add the authenticate function in aedes options

It suppose that these properties should be defaults or optional, also the docs doesn't offer explanation of what properties have or what is PublishPacket

Yeah them are not mandatory, I think types could be improved here. Would you like to submit a PR to fix them?

@robertsLando
Copy link
Member

Fixed by #687

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

No branches or pull requests

2 participants