Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IncomingMessage should implement ReadableStream #170

Open
andersk opened this issue Jul 9, 2020 · 3 comments
Open

IncomingMessage should implement ReadableStream #170

andersk opened this issue Jul 9, 2020 · 3 comments

Comments

@andersk
Copy link

andersk commented Jul 9, 2020

(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’s guarantee that “IncomingMessage implements the Readable Stream interface”:

  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<string, string[]>;
    httpVersion: string;
    httpVersionMajor: number;
    httpVersionMinor: number;
    statusCode: number;
    statusMessage: string;
  }

So working code like this fails to type check:

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();
});
@MarshallOfSound
Copy link
Member

Refs: electron/electron#22730

@andersk
Copy link
Author

andersk commented Oct 8, 2022

Still an issue in Electron 21.1.0, 22.0.0-alpha.3, and 23.0.0-nightly.20221007.

@efattal
Copy link

efattal commented Feb 1, 2023

The confusing part is that the docs stands that "IncomingMessage implements the Readable Stream...". So we can expect that the stream is usable like any other ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants