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

fix: Special case ReadableStream type to mean Node.js ReadableStream #99

Merged
merged 2 commits into from Aug 13, 2018

Conversation

niik
Copy link
Contributor

@niik niik commented May 9, 2018

The StreamProtocolResponse.data property is supposed to be a Node.js readable stream.

Unfortunately the ReadableStream type is ambiguous between the Node.js ReadableStream and the ReadableStream interface defined in the web Streams standard and since the web stream standard is part of the standard lib in TS it'll choose that.

This PR special cases the ReadableStream type name to qualify it with the Node.js namespace.

I wasn't sure what the best approach here would be, special case it in the definition generator or update the documentation to be explicit about the type.

I'm happy to drop this and PR a change to the docs if you'd like.

Diff of generated definitions before/after this change

--- electron.d.ts       2018-05-09 14:42:49.000000000 +0200
+++ electron-niik.d.ts  2018-05-09 14:48:05.000000000 +0200
@@ -3468,7 +3468,7 @@
      * Same as protocol.registerStreamProtocol, except that it replaces an existing
      * protocol handler.
      */
-    interceptStreamProtocol(scheme: string, handler: (request: InterceptStreamProtocolRequest, callback: (stream?: ReadableStream | StreamProtocolResponse) => void) => void, completion?: (error: Error) => void): void;
+    interceptStreamProtocol(scheme: string, handler: (request: InterceptStreamProtocolRequest, callback: (stream?: NodeJS.ReadableStream | StreamProtocolResponse) => void) => void, completion?: (error: Error) => void): void;
     /**
      * Intercepts scheme protocol and uses handler as the protocol's new handler which
      * sends a String as a response.
@@ -3537,7 +3537,7 @@
      * that implements the readable stream API (emits data/end/error events). For
      * example, here's how a file could be returned:
      */
-    registerStreamProtocol(scheme: string, handler: (request: RegisterStreamProtocolRequest, callback: (stream?: ReadableStream | StreamProtocolResponse) => void) => void, completion?: (error: Error) => void): void;
+    registerStreamProtocol(scheme: string, handler: (request: RegisterStreamProtocolRequest, callback: (stream?: NodeJS.ReadableStream | StreamProtocolResponse) => void) => void, completion?: (error: Error) => void): void;
     /**
      * Registers a protocol of scheme that will send a String as a response. The usage
      * is the same with registerFileProtocol, except that the callback should be called
@@ -3951,7 +3951,7 @@
     /**
      * A Node.js readable stream representing the response body
      */
-    data: ReadableStream;
+    data: NodeJS.ReadableStream;
     /**
      * An object containing the response headers
      */

cc @zeke

Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for finding this and proposing a fix!

I like your second offer better, dropping this PR and fixing the docs directly, since changing a few lines of docs is better long-term than adding more special cases to your typescript definitions.

Closing this PR because of that rationale, but I'd be happy to approve & merge a PR on the docs themselves. Thank you!

@ckerr ckerr closed this May 9, 2018
@ckerr
Copy link
Member

ckerr commented May 9, 2018

Reopening after talking it over with @MarshallOfSound 😃 -- let's do it this way

@ckerr ckerr reopened this May 9, 2018
niik added a commit to niik/electron-docs-linter that referenced this pull request May 9, 2018
This adds support for qualified namespaced types in parameters. I.e. you can now write `NodeJS.ReadableStream`.

See electron/typescript-definitions#99 and
@niik
Copy link
Contributor Author

niik commented May 9, 2018

Reopening after talking it over with @MarshallOfSound 😃 -- let's do it this way

Cool. Turns out that there was a bit more to it than "changing a few lines of docs" 😛. First I found that I had to modify the parser in electron-docs-linter to support qualified type names. Once that was done I found a few discrepancies in the docs themselves on master that caused the electron-typescript-definitions build to fail and finally there was a test case that was failing due to electron/electron#12782.

Let me know which ones (if any) of these branches you'd want me to upstream. I'd imagine you'd want the docs changes (minus the qualified type on ReadableStream) and the failing test at least

@MarshallOfSound
Copy link
Member

@niik

I'd imagine you'd want the docs changes (minus the qualified type on ReadableStream) and the failing test at least

Yup 😀That would be awesome 👍

Copy link
Contributor

@zeke zeke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks, @niik 👍

@niik
Copy link
Contributor Author

niik commented May 11, 2018

Yup 😀That would be awesome 👍

Opened electron/electron#12899 and #101

@niik
Copy link
Contributor Author

niik commented Aug 13, 2018

Hey friends, I forgot about this PR until I tried to use the API again and hit the same type error. @ckerr Is there anything more you need from me on this or are we good to merge?

@zeke zeke changed the title Special case ReadableStream type to mean Node.js ReadableStream fix: Special case ReadableStream type to mean Node.js ReadableStream Aug 13, 2018
@zeke
Copy link
Contributor

zeke commented Aug 13, 2018

I prepended fix: to the PR title to make sure this triggers a semantic release.

semantic-pull-requests is installed on this repo, but this PR predates it so the status check is not showing up.

To whomever merges this PR, please squash. 🎃

@ckerr ckerr merged commit d5fc6b5 into electron:master Aug 13, 2018
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

Successfully merging this pull request may close these issues.

None yet

4 participants