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(streams): reject string in ReadableStream.from type #25116

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
2 changes: 1 addition & 1 deletion cli/tsc/dts/lib.dom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18277,7 +18277,7 @@ declare var ReadableStream: {
new(underlyingSource: UnderlyingByteSource, strategy?: { highWaterMark?: number }): ReadableStream<Uint8Array>;
new<R = any>(underlyingSource: UnderlyingDefaultSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>;
new<R = any>(underlyingSource?: UnderlyingSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>;
from<R>(asyncIterable: AsyncIterable<R> | Iterable<R | PromiseLike<R>>): ReadableStream<R>;
from<R>(asyncIterable: AsyncIterable<R> | Iterable<R | PromiseLike<R>> & object): ReadableStream<R>;
};

/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader) */
Expand Down
4 changes: 2 additions & 2 deletions ext/web/06_streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -2922,7 +2922,7 @@ function readableStreamPipeTo(
}

/**
* @param {ReadableStreamGenericReader<any> | ReadableStreamBYOBReader} reader
* @param {ReadableStreamGenericReader | ReadableStreamBYOBReader} reader
* @param {any} reason
* @returns {Promise<void>}
*/
Expand Down Expand Up @@ -2955,7 +2955,7 @@ function readableStreamReaderGenericInitialize(reader, stream) {

/**
* @template R
* @param {ReadableStreamGenericReader<R> | ReadableStreamBYOBReader} reader
* @param {ReadableStreamGenericReader | ReadableStreamBYOBReader} reader
*/
function readableStreamReaderGenericRelease(reader) {
const stream = reader[_stream];
Expand Down
4 changes: 2 additions & 2 deletions ext/web/06_streams_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ interface VoidFunction {
(): void;
}

interface ReadableStreamGenericReader<T> {
readonly closed: Promise<void>;
interface ReadableStreamGenericReader {
readonly closed: Promise<undefined>;
Comment on lines -63 to +64
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed differences with lib.dom.d.ts

// deno-lint-ignore no-explicit-any
cancel(reason?: any): Promise<void>;
}
Expand Down
2 changes: 1 addition & 1 deletion ext/web/lib.deno_web.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ declare var ReadableStream: {
strategy?: QueuingStrategy<R>,
): ReadableStream<R>;
from<R>(
asyncIterable: AsyncIterable<R> | Iterable<R | PromiseLike<R>>,
asyncIterable: AsyncIterable<R> | Iterable<R | PromiseLike<R>> & object,
): ReadableStream<R>;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"args": "check ./main.ts",
"output": "main.out",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Check [WILDCARD]/main.ts
error: TS2345 [ERROR]: Argument of type 'string' is not assignable to parameter of type 'AsyncIterable<string> | (Iterable<string | PromiseLike<string>> & object)'.
ReadableStream.from("string");
~~~~~~~~
at [WILDCARD]/main.ts:1:21
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ReadableStream.from("string");
1 change: 1 addition & 0 deletions tests/unit/streams_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ Deno.test(async function decompressionStreamInvalidGzipStillReported() {

Deno.test(function readableStreamFromWithStringThrows() {
assertThrows(
// @ts-expect-error: primitives are not acceptable
() => ReadableStream.from("string"),
TypeError,
"Failed to execute 'ReadableStream.from': Argument 1 can not be converted to async iterable.",
Expand Down