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

@types/node: stream.pipeline() should accept iterators since Node 13.10 #49868

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion types/node/stream.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,11 @@ declare module 'stream' {
function __promisify__(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, options?: FinishedOptions): Promise<void>;
}

function pipeline<T extends NodeJS.WritableStream>(stream1: NodeJS.ReadableStream, stream2: T, callback?: (err: NodeJS.ErrnoException | null) => void): T;
function pipeline<T extends NodeJS.WritableStream>(
stream1: NodeJS.ReadableStream | Iterable<any> | AsyncIterable<any>,
voxpelli marked this conversation as resolved.
Show resolved Hide resolved
stream2: T,
callback?: (err: NodeJS.ErrnoException | null) => void
): T;
function pipeline<T extends NodeJS.WritableStream>(stream1: NodeJS.ReadableStream, stream2: NodeJS.ReadWriteStream, stream3: T, callback?: (err: NodeJS.ErrnoException | null) => void): T;
function pipeline<T extends NodeJS.WritableStream>(
stream1: NodeJS.ReadableStream,
Expand Down
13 changes: 13 additions & 0 deletions types/node/test/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ function streamPipelineFinished() {
pipeline(process.stdin, process.stdout, (err?: Error | null) => {});
}

function pipelineIterator() {
const iterator = ['foo', 'bar'];
pipeline(iterator, process.stdout, (err?: Error | null) => {});
}

function pipelineAsyncIterator() {
const asyncGenerator = async function*() {
yield 'foo';
yield 'bar';
};
pipeline(asyncGenerator(), process.stdout, (err?: Error | null) => {});
}

async function asyncStreamPipelineFinished() {
const fin = promisify(finished);
await fin(process.stdin);
Expand Down