From aaad240e85ec37ce482afead04d469404a4657ef Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Wed, 21 Aug 2024 04:10:57 +0900 Subject: [PATCH 1/4] tweak --- ext/web/06_streams.js | 4 ++-- ext/web/06_streams_types.d.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index f29e5f204009be..57a437e4f5c304 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -2922,7 +2922,7 @@ function readableStreamPipeTo( } /** - * @param {ReadableStreamGenericReader | ReadableStreamBYOBReader} reader + * @param {ReadableStreamGenericReader | ReadableStreamBYOBReader} reader * @param {any} reason * @returns {Promise} */ @@ -2955,7 +2955,7 @@ function readableStreamReaderGenericInitialize(reader, stream) { /** * @template R - * @param {ReadableStreamGenericReader | ReadableStreamBYOBReader} reader + * @param {ReadableStreamGenericReader | ReadableStreamBYOBReader} reader */ function readableStreamReaderGenericRelease(reader) { const stream = reader[_stream]; diff --git a/ext/web/06_streams_types.d.ts b/ext/web/06_streams_types.d.ts index e04f568d26644a..fe05ee6e65b167 100644 --- a/ext/web/06_streams_types.d.ts +++ b/ext/web/06_streams_types.d.ts @@ -60,8 +60,8 @@ interface VoidFunction { (): void; } -interface ReadableStreamGenericReader { - readonly closed: Promise; +interface ReadableStreamGenericReader { + readonly closed: Promise; // deno-lint-ignore no-explicit-any cancel(reason?: any): Promise; } From 73f866c643e20df8e19108bd4cc5d3613e746cde Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Wed, 21 Aug 2024 04:11:51 +0900 Subject: [PATCH 2/4] fix: reject string in `ReadableStream.from --- cli/tsc/dts/lib.dom.d.ts | 2 +- ext/web/lib.deno_web.d.ts | 2 +- .../reject_string_in_readable_stream_from/__test__.jsonc | 5 +++++ .../check/reject_string_in_readable_stream_from/main.out | 5 +++++ .../check/reject_string_in_readable_stream_from/main.ts | 1 + 5 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/specs/check/reject_string_in_readable_stream_from/__test__.jsonc create mode 100644 tests/specs/check/reject_string_in_readable_stream_from/main.out create mode 100644 tests/specs/check/reject_string_in_readable_stream_from/main.ts diff --git a/cli/tsc/dts/lib.dom.d.ts b/cli/tsc/dts/lib.dom.d.ts index 0a2f9b9edaa6e0..2684735597a37a 100644 --- a/cli/tsc/dts/lib.dom.d.ts +++ b/cli/tsc/dts/lib.dom.d.ts @@ -18277,7 +18277,7 @@ declare var ReadableStream: { new(underlyingSource: UnderlyingByteSource, strategy?: { highWaterMark?: number }): ReadableStream; new(underlyingSource: UnderlyingDefaultSource, strategy?: QueuingStrategy): ReadableStream; new(underlyingSource?: UnderlyingSource, strategy?: QueuingStrategy): ReadableStream; - from(asyncIterable: AsyncIterable | Iterable>): ReadableStream; + from(asyncIterable: AsyncIterable | Iterable> & object): ReadableStream; }; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader) */ diff --git a/ext/web/lib.deno_web.d.ts b/ext/web/lib.deno_web.d.ts index 2ad97ac7d1eef2..8aafbad535923a 100644 --- a/ext/web/lib.deno_web.d.ts +++ b/ext/web/lib.deno_web.d.ts @@ -882,7 +882,7 @@ declare var ReadableStream: { strategy?: QueuingStrategy, ): ReadableStream; from( - asyncIterable: AsyncIterable | Iterable>, + asyncIterable: AsyncIterable | Iterable> & object, ): ReadableStream; }; diff --git a/tests/specs/check/reject_string_in_readable_stream_from/__test__.jsonc b/tests/specs/check/reject_string_in_readable_stream_from/__test__.jsonc new file mode 100644 index 00000000000000..634dbac8503ab5 --- /dev/null +++ b/tests/specs/check/reject_string_in_readable_stream_from/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "check ./main.ts", + "output": "main.out", + "exitCode": 1 +} diff --git a/tests/specs/check/reject_string_in_readable_stream_from/main.out b/tests/specs/check/reject_string_in_readable_stream_from/main.out new file mode 100644 index 00000000000000..577c1fb059df7f --- /dev/null +++ b/tests/specs/check/reject_string_in_readable_stream_from/main.out @@ -0,0 +1,5 @@ +Check [WILDCARD]/main.ts +error: TS2345 [ERROR]: Argument of type 'string' is not assignable to parameter of type 'AsyncIterable | (Iterable> & object)'. +ReadableStream.from("string"); + ~~~~~~~~ + at [WILDCARD]/main.ts:1:21 diff --git a/tests/specs/check/reject_string_in_readable_stream_from/main.ts b/tests/specs/check/reject_string_in_readable_stream_from/main.ts new file mode 100644 index 00000000000000..5e7fc9c9563ec5 --- /dev/null +++ b/tests/specs/check/reject_string_in_readable_stream_from/main.ts @@ -0,0 +1 @@ +ReadableStream.from("string"); From 5867a8c0306019ea8bd7e594fa84b9f370db4221 Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Wed, 21 Aug 2024 04:31:20 +0900 Subject: [PATCH 3/4] fix --- tests/unit/streams_test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/streams_test.ts b/tests/unit/streams_test.ts index 73f9a60953c84b..fb18616939cd53 100644 --- a/tests/unit/streams_test.ts +++ b/tests/unit/streams_test.ts @@ -541,6 +541,7 @@ Deno.test(async function decompressionStreamInvalidGzipStillReported() { Deno.test(function readableStreamFromWithStringThrows() { assertThrows( + // @ts-expect-error () => ReadableStream.from("string"), TypeError, "Failed to execute 'ReadableStream.from': Argument 1 can not be converted to async iterable.", From 71df4fd84dec69f90753bb604477c731fda81329 Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Sat, 16 Nov 2024 05:30:27 +0900 Subject: [PATCH 4/4] lint --- tests/unit/streams_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/streams_test.ts b/tests/unit/streams_test.ts index fb18616939cd53..53225a1553c6a3 100644 --- a/tests/unit/streams_test.ts +++ b/tests/unit/streams_test.ts @@ -541,7 +541,7 @@ Deno.test(async function decompressionStreamInvalidGzipStillReported() { Deno.test(function readableStreamFromWithStringThrows() { assertThrows( - // @ts-expect-error + // @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.",