Skip to content

fix(util-stream): avoid compilation of type parameter in global ReadableStream #1343

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

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/forty-candles-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@smithy/eventstream-serde-browser": patch
"@smithy/util-stream": patch
---

avoid compilation of global ReadableStream with type parameter
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,11 @@ export class EventStreamMarshaller {
}
}

/**
* @internal
* Warning: do not export this without aliasing the reference to
* global ReadableStream.
* @see https://github.com/smithy-lang/smithy-typescript/issues/1341.
*/
const isReadableStream = (body: any): body is ReadableStream =>
typeof ReadableStream === "function" && body instanceof ReadableStream;
10 changes: 9 additions & 1 deletion packages/util-stream/src/stream-type-check.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/**
* @internal
* Alias prevents compiler from turning
* ReadableStream into ReadableStream<any>, which is incompatible
* with the NodeJS.ReadableStream global type.
*/
export const isReadableStream = (stream: unknown): stream is ReadableStream =>
type ReadableStreamType = ReadableStream;

/**
* @internal
*/
export const isReadableStream = (stream: unknown): stream is ReadableStreamType =>
typeof ReadableStream === "function" &&
(stream?.constructor?.name === ReadableStream.name || stream instanceof ReadableStream);
Loading