No longer compiles with tsc
When anything that uses promise-socket is compiled with the TypeScript compiler (tsc), the following error occurs:
node_modules/promise-socket/node_modules/promise-duplex/lib/promise-duplex.d.ts:6:11 - error TS2430: Interface 'DuplexStream' incorrectly extends interface 'Duplex'.
Property 'closed' is optional in type 'DuplexStream' but required in type 'Duplex'.
6 interface DuplexStream extends Duplex {
~~~~~~~~~~~~
Found 1 error.
This is because the dependency package promise-duplex (published by the same github user) incorrectly extends the Duplex class in the promise-duplex.ts file.
A child class cannot change the required-ness of a property that exists in a parent class to make it optional when it is required in the parent class. TypeScript requires that child classes must implement the entire contract of a parent class. If a field is required in the parent, it must be required in the child.
I've created a similar issue in the promise-duplex project: https://github.com/dex4er/js-promise-duplex/issues/61
But I'm posting it here so users know this package is a dead-end until this is fixed.
Yep, broken for me too. I came up with this snippet which covers my needs for now.
class PromiseSocket {
constructor(private innerSok: net.Socket) {}
public connect(port: number, host: string): Promise<void> {
return new Promise((resolve, reject) => {
this.innerSok.connect(port, host, () => {
resolve();
});
this.innerSok.on('error', err => {
reject(err);
});
});
}
async write(data: string) {
return new Promise<void>((resolve, reject) => {
this.innerSok.write(data, () => {
resolve();
});
this.innerSok.on('error', err => {
reject(err);
});
});
}
async readAll() {
return new Promise<string>((resolve, reject) => {
let buf = '';
this.innerSok.on('data', data => {
buf += data;
});
this.innerSok.on('error', err => {
reject(err);
});
this.innerSok.on('end', () => {
resolve(buf);
});
});
}
}
Fixed in https://github.com/dex4er/js-promise-socket/releases/tag/v8.0.0