Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating added types for ReadableStreamReadDoneResult #1676

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions baselines/audioworklet.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ interface ReadableStreamGetReaderOptions {
mode?: ReadableStreamReaderMode;
}

interface ReadableStreamReadDoneResult<T> {
done: true;
value?: T;
}

interface ReadableStreamReadValueResult<T> {
done: false;
value: T;
Expand Down Expand Up @@ -775,7 +770,7 @@ declare var ReadableStream: {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader) */
interface ReadableStreamBYOBReader extends ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/read) */
read<T extends ArrayBufferView>(view: T): Promise<ReadableStreamReadResult<T>>;
read<T extends ArrayBufferView>(view: T): Promise<ReadableStreamBYOBReadResult<T>>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/releaseLock) */
releaseLock(): void;
}
Expand Down Expand Up @@ -820,7 +815,7 @@ declare var ReadableStreamDefaultController: {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader) */
interface ReadableStreamDefaultReader<R = any> extends ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader/read) */
read(): Promise<ReadableStreamReadResult<R>>;
read(): Promise<ReadableStreamDefaultReadResult<R>>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader/releaseLock) */
releaseLock(): void;
}
Expand Down Expand Up @@ -1408,8 +1403,10 @@ type BufferSource = ArrayBufferView | ArrayBuffer;
type DOMHighResTimeStamp = number;
type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
type MessageEventSource = MessagePort;
type ReadableStreamBYOBReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamBYOBReadDoneResult<T>;
type ReadableStreamController<T> = ReadableStreamDefaultController<T> | ReadableByteStreamController;
type ReadableStreamReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamReadDoneResult<T>;
type ReadableStreamDefaultReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamDefaultReadDoneResult;
type ReadableStreamReadResult<T> = ReadableStreamDefaultReadResult<T> | ReadableStreamBYOBReadResult<T>;
type ReadableStreamReader<T> = ReadableStreamDefaultReader<T> | ReadableStreamBYOBReader;
type Transferable = MessagePort | ReadableStream | WritableStream | TransformStream | ArrayBuffer;
type CompressionFormat = "deflate" | "deflate-raw" | "gzip";
Expand Down
13 changes: 5 additions & 8 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1619,11 +1619,6 @@ interface ReadableStreamGetReaderOptions {
mode?: ReadableStreamReaderMode;
}

interface ReadableStreamReadDoneResult<T> {
done: true;
value?: T;
}

interface ReadableStreamReadValueResult<T> {
done: false;
value: T;
Expand Down Expand Up @@ -18633,7 +18628,7 @@ declare var ReadableStream: {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader) */
interface ReadableStreamBYOBReader extends ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/read) */
read<T extends ArrayBufferView>(view: T): Promise<ReadableStreamReadResult<T>>;
read<T extends ArrayBufferView>(view: T): Promise<ReadableStreamBYOBReadResult<T>>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/releaseLock) */
releaseLock(): void;
}
Expand Down Expand Up @@ -18678,7 +18673,7 @@ declare var ReadableStreamDefaultController: {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader) */
interface ReadableStreamDefaultReader<R = any> extends ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader/read) */
read(): Promise<ReadableStreamReadResult<R>>;
read(): Promise<ReadableStreamDefaultReadResult<R>>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader/releaseLock) */
releaseLock(): void;
}
Expand Down Expand Up @@ -28203,8 +28198,10 @@ type OptionalPostfixToken<T extends string> = ` ${T}` | "";
type OptionalPrefixToken<T extends string> = `${T} ` | "";
type PerformanceEntryList = PerformanceEntry[];
type RTCRtpTransform = RTCRtpScriptTransform;
type ReadableStreamBYOBReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamBYOBReadDoneResult<T>;
type ReadableStreamController<T> = ReadableStreamDefaultController<T> | ReadableByteStreamController;
type ReadableStreamReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamReadDoneResult<T>;
type ReadableStreamDefaultReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamDefaultReadDoneResult;
type ReadableStreamReadResult<T> = ReadableStreamDefaultReadResult<T> | ReadableStreamBYOBReadResult<T>;
type ReadableStreamReader<T> = ReadableStreamDefaultReader<T> | ReadableStreamBYOBReader;
type RenderingContext = CanvasRenderingContext2D | ImageBitmapRenderingContext | WebGLRenderingContext | WebGL2RenderingContext;
type ReportList = Report[];
Expand Down
13 changes: 5 additions & 8 deletions baselines/serviceworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,6 @@ interface ReadableStreamGetReaderOptions {
mode?: ReadableStreamReaderMode;
}

interface ReadableStreamReadDoneResult<T> {
done: true;
value?: T;
}

interface ReadableStreamReadValueResult<T> {
done: false;
value: T;
Expand Down Expand Up @@ -4524,7 +4519,7 @@ declare var ReadableStream: {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader) */
interface ReadableStreamBYOBReader extends ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/read) */
read<T extends ArrayBufferView>(view: T): Promise<ReadableStreamReadResult<T>>;
read<T extends ArrayBufferView>(view: T): Promise<ReadableStreamBYOBReadResult<T>>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/releaseLock) */
releaseLock(): void;
}
Expand Down Expand Up @@ -4569,7 +4564,7 @@ declare var ReadableStreamDefaultController: {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader) */
interface ReadableStreamDefaultReader<R = any> extends ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader/read) */
read(): Promise<ReadableStreamReadResult<R>>;
read(): Promise<ReadableStreamDefaultReadResult<R>>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader/releaseLock) */
releaseLock(): void;
}
Expand Down Expand Up @@ -8575,8 +8570,10 @@ type OffscreenRenderingContext = OffscreenCanvasRenderingContext2D | ImageBitmap
type OnErrorEventHandler = OnErrorEventHandlerNonNull | null;
type PerformanceEntryList = PerformanceEntry[];
type PushMessageDataInit = BufferSource | string;
type ReadableStreamBYOBReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamBYOBReadDoneResult<T>;
type ReadableStreamController<T> = ReadableStreamDefaultController<T> | ReadableByteStreamController;
type ReadableStreamReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamReadDoneResult<T>;
type ReadableStreamDefaultReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamDefaultReadDoneResult;
type ReadableStreamReadResult<T> = ReadableStreamDefaultReadResult<T> | ReadableStreamBYOBReadResult<T>;
type ReadableStreamReader<T> = ReadableStreamDefaultReader<T> | ReadableStreamBYOBReader;
type ReportList = Report[];
type RequestInfo = Request | string;
Expand Down
13 changes: 5 additions & 8 deletions baselines/sharedworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,6 @@ interface ReadableStreamGetReaderOptions {
mode?: ReadableStreamReaderMode;
}

interface ReadableStreamReadDoneResult<T> {
done: true;
value?: T;
}

interface ReadableStreamReadValueResult<T> {
done: false;
value: T;
Expand Down Expand Up @@ -4358,7 +4353,7 @@ declare var ReadableStream: {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader) */
interface ReadableStreamBYOBReader extends ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/read) */
read<T extends ArrayBufferView>(view: T): Promise<ReadableStreamReadResult<T>>;
read<T extends ArrayBufferView>(view: T): Promise<ReadableStreamBYOBReadResult<T>>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/releaseLock) */
releaseLock(): void;
}
Expand Down Expand Up @@ -4403,7 +4398,7 @@ declare var ReadableStreamDefaultController: {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader) */
interface ReadableStreamDefaultReader<R = any> extends ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader/read) */
read(): Promise<ReadableStreamReadResult<R>>;
read(): Promise<ReadableStreamDefaultReadResult<R>>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader/releaseLock) */
releaseLock(): void;
}
Expand Down Expand Up @@ -8581,8 +8576,10 @@ type NamedCurve = string;
type OffscreenRenderingContext = OffscreenCanvasRenderingContext2D | ImageBitmapRenderingContext | WebGLRenderingContext | WebGL2RenderingContext;
type OnErrorEventHandler = OnErrorEventHandlerNonNull | null;
type PerformanceEntryList = PerformanceEntry[];
type ReadableStreamBYOBReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamBYOBReadDoneResult<T>;
type ReadableStreamController<T> = ReadableStreamDefaultController<T> | ReadableByteStreamController;
type ReadableStreamReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamReadDoneResult<T>;
type ReadableStreamDefaultReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamDefaultReadDoneResult;
type ReadableStreamReadResult<T> = ReadableStreamDefaultReadResult<T> | ReadableStreamBYOBReadResult<T>;
type ReadableStreamReader<T> = ReadableStreamDefaultReader<T> | ReadableStreamBYOBReader;
type ReportList = Report[];
type RequestInfo = Request | string;
Expand Down
13 changes: 5 additions & 8 deletions baselines/webworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,6 @@ interface ReadableStreamGetReaderOptions {
mode?: ReadableStreamReaderMode;
}

interface ReadableStreamReadDoneResult<T> {
done: true;
value?: T;
}

interface ReadableStreamReadValueResult<T> {
done: false;
value: T;
Expand Down Expand Up @@ -4848,7 +4843,7 @@ declare var ReadableStream: {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader) */
interface ReadableStreamBYOBReader extends ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/read) */
read<T extends ArrayBufferView>(view: T): Promise<ReadableStreamReadResult<T>>;
read<T extends ArrayBufferView>(view: T): Promise<ReadableStreamBYOBReadResult<T>>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/releaseLock) */
releaseLock(): void;
}
Expand Down Expand Up @@ -4893,7 +4888,7 @@ declare var ReadableStreamDefaultController: {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader) */
interface ReadableStreamDefaultReader<R = any> extends ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader/read) */
read(): Promise<ReadableStreamReadResult<R>>;
read(): Promise<ReadableStreamDefaultReadResult<R>>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader/releaseLock) */
releaseLock(): void;
}
Expand Down Expand Up @@ -9308,8 +9303,10 @@ type OffscreenRenderingContext = OffscreenCanvasRenderingContext2D | ImageBitmap
type OnErrorEventHandler = OnErrorEventHandlerNonNull | null;
type PerformanceEntryList = PerformanceEntry[];
type PushMessageDataInit = BufferSource | string;
type ReadableStreamBYOBReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamBYOBReadDoneResult<T>;
type ReadableStreamController<T> = ReadableStreamDefaultController<T> | ReadableByteStreamController;
type ReadableStreamReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamReadDoneResult<T>;
type ReadableStreamDefaultReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamDefaultReadDoneResult;
type ReadableStreamReadResult<T> = ReadableStreamDefaultReadResult<T> | ReadableStreamBYOBReadResult<T>;
type ReadableStreamReader<T> = ReadableStreamDefaultReader<T> | ReadableStreamBYOBReader;
type ReportList = Report[];
type RequestInfo = Request | string;
Expand Down
60 changes: 56 additions & 4 deletions inputfiles/addedTypes.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,23 @@
}
},
"ReadableStreamReadDoneResult": {
"name": "ReadableStreamReadDoneResult",
"members": {
"member": {
"done": {
"name": "done",
"overrideType": "true",
"required": true
},
"value": {
"name": "value",
"overrideType": "undefined",
"required": true
}
}
}
},
"ReadableStreamBYOBReadDoneResult": {
"name": "ReadableStreamReadDoneResult",
"typeParameters": [
{
Expand All @@ -1303,7 +1320,8 @@
},
"value": {
"name": "value",
"overrideType": "T"
"overrideType": "T",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadableStreamBYOBReadDoneResult.value should be T | undefined, as per spec:

If the reader is canceled, the promise will be fulfilled with an object of the form { value: undefined, done: true }. In this case, the backing memory region of view is discarded and not returned to the caller.

See also: Deno and web-streams-polyfill.

"required": true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we make value: T | undefined, should we also make it optional? Or does that not work well together with exactOptionalPropertyTypes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, the spec is pretty clear that the value property would exist: https://streams.spec.whatwg.org/#default-reader-read

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's for default readers. For BYOB readers, the spec is at https://streams.spec.whatwg.org/#byob-reader-read.

But still, that doesn't explain where chunk is coming from. When a stream is cancelled while it has a BYOB reader attached, ReadableStreamCancel resolves all pending read(view) promises with { done: true, value: undefined }:

  1. If reader is not undefined and reader implements ReadableStreamBYOBReader,
    6.3. For each readIntoRequest of readIntoRequests,
    6.3.1. Perform readIntoRequest’s close steps, given undefined.

Copy link
Author

@kraenhansen kraenhansen Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Reading the spec you've linked to, it seems pretty explicit (list item 9) that the value property will be in the object returned from read, even from a ReadableStreamBYOBReader.

}
}
}
Expand Down Expand Up @@ -1521,7 +1539,7 @@
]
},
{
"name": "ReadableStreamReadResult",
"name": "ReadableStreamDefaultReadResult",
"typeParameters": [
{
"name": "T"
Expand All @@ -1532,10 +1550,44 @@
"type": "ReadableStreamReadValueResult"
},
{
"type": "ReadableStreamReadDoneResult"
"type": "ReadableStreamDefaultReadDoneResult"
}
],
"overrideType": "ReadableStreamReadValueResult<T> | ReadableStreamDefaultReadDoneResult"
},
{
"name": "ReadableStreamBYOBReadResult",
"typeParameters": [
{
"name": "T"
}
],
"type": [
{
"type": "ReadableStreamReadValueResult"
},
{
"type": "ReadableStreamBYOBReadDoneResult"
}
],
"overrideType": "ReadableStreamReadValueResult<T> | ReadableStreamBYOBReadDoneResult<T>"
},
{
"name": "ReadableStreamReadResult",
"typeParameters": [
{
"name": "T"
}
],
"type": [
{
"type": "ReadableStreamDefaultReadResult"
},
{
"type": "ReadableStreamBYOBReadResult"
}
],
"overrideType": "ReadableStreamReadValueResult<T> | ReadableStreamReadDoneResult<T>"
"overrideType": "ReadableStreamDefaultReadResult<T> | ReadableStreamBYOBReadResult<T>"
},
{
"name": "EventListenerOrEventListenerObject",
Expand Down
4 changes: 2 additions & 2 deletions inputfiles/overridingTypes.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2652,7 +2652,7 @@
"overrideType": "T"
}
],
"overrideType": "Promise<ReadableStreamReadResult<T>>"
"overrideType": "Promise<ReadableStreamBYOBReadResult<T>>"
}
}
}
Expand Down Expand Up @@ -2690,7 +2690,7 @@
"read": {
"signature": {
"0": {
"overrideType": "Promise<ReadableStreamReadResult<R>>"
"overrideType": "Promise<ReadableStreamDefaultReadResult<R>>"
}
}
}
Expand Down
Loading