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

[bug] TypeScript error due to incompatible aedes.handle function for Node net module v16 #801

Open
haci-xplora opened this issue Dec 27, 2022 · 3 comments
Labels

Comments

@haci-xplora
Copy link

haci-xplora commented Dec 27, 2022

System Information

  • Aedes: 0.48.1
  • NodeJS: 16.18.1
  • TypeScript: 4.9.4
  • OS: MacOS Ventura 13.1
  • Arch: Apple M1

Describe the bug
Function aedes.handle is not compatible with listener for net.createServer. So, it causes TypeScript compile error.

Sample code:

import Aedes from 'aedes';
import { createServer } from 'net';
const mqttServer = new Aedes();
const netServer = createServer(mqttServer.handle);
netServer.listen(1883, () => {
  console.info('ready at 1883');
});

Error:

src/index.ts:4:32 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(connectionListener?: ((socket: Socket) => void) | undefined): Server', gave the following error.
    Argument of type '(stream: Connection, request: IncomingMessage) => Client' is not assignable to parameter of type '(socket: Socket) => void'.
  Overload 2 of 2, '(options?: ServerOpts | undefined, connectionListener?: ((socket: Socket) => void) | undefined): Server', gave the following error.
    Type '(stream: Connection, request: IncomingMessage) => Client' has no properties in common with type 'ServerOpts'.

4 const netServer = createServer(mqttServer.handle);
                                 ~~~~~~~~~~~~~~~~~
Found 1 error.

To Reproduce
Steps to reproduce the behavior is not much different than the sample code on Examples page

  1. try to compile project with sample code

Expected behavior
Project should compile as expected without any errors.

@robertsLando
Copy link
Member

@haci-xplora this is a type issue, could you please send a PR to fix it?

@haci-xplora
Copy link
Author

haci-xplora commented Dec 28, 2022

hi Robert.

the type of handle function is based on the signature of implementation, so it is correct. but if request parameter (IncomingMessage) is not in use (as I can see it is not used), it should be omitted. that is why it should not be assigned as listener of net server. shall I do that and remove request parameter?

or we can make it optional/nullable.

otherwise, multiple adapter clients are needed for net server, and other servers like websocket server.
see Client.md
it says request parameter is for that.

one class cannot handle those variations well.

let me create a PR and discuss further.

@haci-xplora
Copy link
Author

request parameter is now optional

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