Skip to content

Commit

Permalink
Fix typings for Node.js <=12
Browse files Browse the repository at this point in the history
Fixes #1350
  • Loading branch information
szmarczak committed Jul 14, 2020
1 parent c833939 commit 61d6f61
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ const waitForOpenFile = async (file: ReadStream): Promise<void> => new Promise((
reject(error);
};

if (!file.pending) {
// Node.js 12 has incomplete types
if (!(file as any).pending) {
resolve();
}

Expand Down Expand Up @@ -1627,11 +1628,10 @@ export default class Request extends Duplex implements RequestEvents<Request> {
}
}

// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
// @ts-ignore Node.js 12 has incorrect typing
_write(chunk: any, encoding: BufferEncoding | undefined, callback: (error?: Error | null) => void): void {
// Node.js 12 has incorrect types, so the encoding must be a string
_write(chunk: any, encoding: string | undefined, callback: (error?: Error | null) => void): void {
const write = (): void => {
this._writeRequest(chunk, encoding, callback);
this._writeRequest(chunk, encoding as BufferEncoding, callback);
};

if (this.requestInitialized) {
Expand Down
3 changes: 2 additions & 1 deletion test/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ test('socket connect listener cleaned up after request', withServer, async (t, s
});
}

for (const value of Object.values(agent.freeSockets) as [Socket[]]) {
// Node.js 12 has incomplete types
for (const value of Object.values((agent as any).freeSockets) as [Socket[]]) {
for (const sock of value) {
t.is(sock.listenerCount('connect'), 0);
}
Expand Down

0 comments on commit 61d6f61

Please sign in to comment.