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:
parent
115a306656
commit
4330ef553f
8 changed files with 18 additions and 6 deletions
2
cli/tsc/dts/lib.dom.d.ts
vendored
2
cli/tsc/dts/lib.dom.d.ts
vendored
|
@ -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) */
|
||||
|
|
|
@ -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];
|
||||
|
|
4
ext/web/06_streams_types.d.ts
vendored
4
ext/web/06_streams_types.d.ts
vendored
|
@ -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>;
|
||||
}
|
||||
|
|
2
ext/web/lib.deno_web.d.ts
vendored
2
ext/web/lib.deno_web.d.ts
vendored
|
@ -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>;
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"args": "check ./main.ts",
|
||||
"output": "main.out",
|
||||
"exitCode": 1
|
||||
}
|
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
ReadableStream.from("string");
|
|
@ -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.",
|
||||
|
|
Loading…
Reference in a new issue