fix(ext/web): fix typings for readable stream readers
* Introduces `ReadableStreamDefaultReadResult` and modifies
`ReadableStreamDefaultReader.read` to return this type (closes
* Adds the missing `ReadableStreamBYOBReader` constructor.
* Removes the nonexistent `ReadableStreamReader` class.
@@ -466,30 +466,36 @@ declare class File extends Blob {
}
/** @category Streams API */
-interface ReadableStreamReadDoneResult<T> {
+interface ReadableStreamDefaultReadDoneResult {
done: true;
- value?: T;
+ value?: undefined;
}
/** @category Streams API */
-interface ReadableStreamReadValueResult<T> {
+interface ReadableStreamDefaultReadValueResult<T> {
done: false;
value: T;
}
/** @category Streams API */
-type ReadableStreamReadResult<T> =
- | ReadableStreamReadValueResult<T>
- | ReadableStreamReadDoneResult<T>;
+type ReadableStreamDefaultReadResult<T> =
+ | ReadableStreamDefaultReadValueResult<T>
+ | ReadableStreamDefaultReadDoneResult;
/** @category Streams API */
interface ReadableStreamDefaultReader<R = any> {
readonly closed: Promise<void>;
cancel(reason?: any): Promise<void>;
- read(): Promise<ReadableStreamReadResult<R>>;
+ read(): Promise<ReadableStreamDefaultReadResult<R>>;
releaseLock(): void;
}
+/** @category Streams API */
+declare var ReadableStreamDefaultReader: {
+ prototype: ReadableStreamDefaultReader;
+ new <R>(stream: ReadableStream<R>): ReadableStreamDefaultReader<R>;
+};
+
/** @category Streams API */
interface ReadableStreamBYOBReadDoneResult<V extends ArrayBufferView> {
done: true;
@@ -517,6 +523,12 @@ interface ReadableStreamBYOBReader {
releaseLock(): void;
}
+/** @category Streams API */
+declare var ReadableStreamBYOBReader: {
+ prototype: ReadableStreamBYOBReader;
+ new (stream: ReadableStream<Uint8Array>): ReadableStreamBYOBReader;
+};
+
/** @category Streams API */
interface ReadableStreamBYOBRequest {
readonly view: ArrayBufferView | null;
@@ -524,25 +536,6 @@ interface ReadableStreamBYOBRequest {
respondWithNewView(view: ArrayBufferView): void;
}
-/** @category Streams API */
-declare var ReadableStreamDefaultReader: {
- prototype: ReadableStreamDefaultReader;
- new <R>(stream: ReadableStream<R>): ReadableStreamDefaultReader<R>;
-};
-
-/** @category Streams API */
-interface ReadableStreamReader<R = any> {
- cancel(): Promise<void>;
- read(): Promise<ReadableStreamReadResult<R>>;
- releaseLock(): void;
-}
-
-/** @category Streams API */
-declare var ReadableStreamReader: {
- prototype: ReadableStreamReader;
- new (): ReadableStreamReader;
-};
-
/** @category Streams API */
interface ReadableByteStreamControllerCallback {
(controller: ReadableByteStreamController): void | PromiseLike<void>;
