1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-02 20:38:47 -05:00

fix(streams): reject string in ReadableStream.from type (#25116)

WebIDL `async iterable<T>` type rejects `string`

Ref https://github.com/whatwg/webidl/pull/1397, #24623
This commit is contained in:
Kenta Moriuchi 2024-11-27 04:42:54 +09:00 committed by GitHub
parent 115a306656
commit 4330ef553f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 18 additions and 6 deletions

View file

@ -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) */

View file

@ -2922,7 +2922,7 @@ function readableStreamPipeTo(
}
/**
* @param {ReadableStreamGenericReader<any> | ReadableStreamBYOBReader} reader
* @param {ReadableStreamGenericReader | ReadableStreamBYOBReader} reader
* @param {any} reason
* @returns {Promise<void>}
*/
@ -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];

View file

@ -60,8 +60,8 @@ interface VoidFunction {
(): void;
}
interface ReadableStreamGenericReader<T> {
readonly closed: Promise<void>;
interface ReadableStreamGenericReader {
readonly closed: Promise<undefined>;
// deno-lint-ignore no-explicit-any
cancel(reason?: any): Promise<void>;
}

View file

@ -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>;
};

View file

@ -0,0 +1,5 @@
{
"args": "check ./main.ts",
"output": "main.out",
"exitCode": 1
}

View file

@ -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

View file

@ -0,0 +1 @@
ReadableStream.from("string");

View file

@ -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.",