You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This allows undefined to be enqueued into the stream while the reader of the stream still expects to read R out of it.
This is demonstrated in the following example:
conststream=newReadableStream<string>({start: (controller)=>{// currently the signature is// ReadableStreamDefaultController<string>.enqueue(chunk?: string | undefined): void// undefined is enqueued herecontroller.enqueue();},});// ReadableStreamDefaultReader<string>constreader=stream.getReader();// ReadableStreamReadResult<string>constresult=awaitreader.read();if(result.done===false){// result is narrowed down to ReadableStreamReadValueResult<string>// TypeScript assumes ReadableStreamReadValueResult<string>.value is string// so the compilation will succeed// but result.value is actually undefinedresult.value.toUpperCase();}
The Web IDL definition specifies an
enqueue
method for the ReadableStreamDefaultController class with the following signature:The
chunk
parameter is optional which probably is fine since chunk isany
.However, this is a little problematic with TypeScript generics.
Currently, the generated TypeScript interface looks like this:
This allows
undefined
to be enqueued into the stream while the reader of the stream still expects to readR
out of it.This is demonstrated in the following example:
To address this, could we consider overriding the
chunk
parameter to be required?There are similar issues with TransformStreamDefaultController.enqueue and WritableStreamDefaultWriter.write.
The text was updated successfully, but these errors were encountered: