TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

`ReadableStream.pipeThrough` should be generic on `transform` argument and return real type of `ReadableStream`

Open yume-chan opened this issue 3 years ago • 1 comments

Sorry if here is not the place to discuss individual API design.

Currently pipeThrough is defined as

https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/11d922f302743cb3fcee9ab59b03d40074a2965c/baselines/dom.generated.d.ts#L11137

It always returns a ReadableStream<T>.

However according to spec it will return transform.readable

The pipeThrough(transform, options) method steps are:

[...]

  1. Return transform["readable"].

https://streams.spec.whatwg.org/#rs-pipe-through

And ReadableStream can be extended

class ReadableFileStream extends ReadableStream {
  constructor(filename) {
    super({ ... use filename to hook up underlying source here ... });
  }
}

The latter [code above] is especially useful if you want to add more methods to each instance, or want to provide a namespace to hang static methods off of, or something.

https://github.com/whatwg/streams/issues/160#issuecomment-50029977

So now we will lost the real type of the ReadableStream.

Should it be override to

pipeThrough<T extends ReadableWritablePair<any, R>>(transform: T, options?: StreamPipeOptions): T["readable"];

Or we need to change IDL first?

yume-chan avatar Feb 17 '22 03:02 yume-chan

Sounds like a good idea to me.

saschanaz avatar Aug 04 '22 07:08 saschanaz