mkozjak / node-telnet-client

A simple telnet client for Node.js
Other
350 stars 97 forks source link

TypeScript: getSocket() wrong return type. #213

Closed ronny332 closed 2 years ago

ronny332 commented 2 years ago

Hi! Thanks for your great work, the library is working like a charm 👍.

One small issue: your index.d.ts shows the return type of "getSocket()" as "Socket". That's right for an open connection, but wrong for an unused Telnet instance. In my eyes it would be better to mark it as:

getSocket(): Socket | undefined;

I have to make a "unnecessary-condition" to get it working with eslint and strict rules:

const isOpen = (): boolean => {
  const socket = connection.getSocket();

  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
  if (socket !== undefined) {
    return socket.readyState === 'open';
  }

  return false;
};

Thank you in advance!

mkozjak commented 2 years ago

Hi, @ronny332, and thank you for your kind words! Care to do a PR?

ronny332 commented 2 years ago

Hi, sure, tommorow should be enough time to get started. Sorry for the delay before this reply.