electron / electron/typescript-definitions

IncomingMessage should implement ReadableStream

Open
#170 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
131
Forks
37
Avg merge
6h
Merged PRs (30d)
2

Description

(Feel free to redirect me if this bug should be reported elsewhere.)

The definition of `IncomingMessage` (generated from https://github.com/electron/electron/releases/download/v9.1.0/electron-api.json) fails to reflect the [documentation](https://www.electronjs.org/docs/api/incoming-message#class-incomingmessage)’s guarantee that “`IncomingMessage` implements the [Readable Stream](https://nodejs.org/api/stream.html#stream_readable_streams) interface”:

```typescript
class IncomingMessage extends NodeEventEmitter {

// Docs: http://electronjs.org/docs/api/incoming-message

/**
* Emitted when a request has been canceled during an ongoing HTTP transaction.
*/
on(event: 'aborted', listener: Function): this;
// …
// more events
// …
removeListener(event: 'error', listener: Function): this;
headers: Record;
httpVersion: string;
httpVersionMajor: number;
httpVersionMinor: number;
statusCode: number;
statusMessage: string;
}
```

So working code like this fails to type check:

```typescript
import { app, net } from "electron";
import getStream from "get-stream";

app.on("ready", () => {
const request = net.request({url: "https://example.com"});
request.on("response", async response => {
if (true) {
// error TS2345: Argument of type 'IncomingMessage' is not assignable to parameter of type 'Stream'.
console.log(await getStream(response));
} else {
// error TS2495: Type 'IncomingMessage' is not an array type or a string type.
for await (const chunk of response) {
console.log(chunk.toString());
}
}
});
request.end();
});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.