Currently, I am in the process of building a basic IRC bot and using raw sockets to connect to the IRC server. Initially written in plain Javascript, I am now transitioning it to TypeScript. However, I have encountered an unusual issue when attempting to connect over TLS (everything functions correctly over a non-secure connection). The source code for my bot can be found on Bitbucket, and the specific problem area lies here:
[...]
this.client = this.tlsEnabled
// @ts-ignore
? new TLSSocket()
: new Socket();
this.client.connect(this.port, this.host, () => {
this.sendInitialConnectionMessages();
});
[...]
Without the @ts-ignore
line, both VS Code and tsc
raise errors regarding the new TLSSocket()
call:
The function expects 1-2 arguments, but none were provided. An argument for 'socket' is missing.
Indeed, the type definition indicates that at least a socket
argument is required.
However, providing this argument—either through new TLSSocket(new Socket())
or by creating a constant with const socket = new Socket()
followed by new TLSSocket(socket)
—causes the script to abruptly stop without reaching the this.client.connect()
call. By instructing tsc
to overlook the absence of arguments for TLSSocket()
as mentioned, everything operates smoothly, and the bot successfully establishes a TLS connection to the server!
I suspect I may be making a simple error somewhere, but I'm uncertain about it. Any assistance would be greatly appreciated!