1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

fix(ext/web): fix typings for readable stream readers (#16191)

* Introduces `ReadableStreamDefaultReadResult` and modifies
`ReadableStreamDefaultReader.read` to return this type (closes #15269).
* Adds the missing `ReadableStreamBYOBReader` constructor.
* Removes the nonexistent `ReadableStreamReader` class.
This commit is contained in:
ud2 2022-11-30 23:24:13 +08:00 committed by GitHub
parent 3f71c0dcf5
commit 972048ce36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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