diff --git a/types/node/stream.d.ts b/types/node/stream.d.ts index 84ce0ea9b551da7..306ddf66384d349 100644 --- a/types/node/stream.d.ts +++ b/types/node/stream.d.ts @@ -1,3 +1,5 @@ +/// + declare module "stream" { import * as events from "events"; @@ -18,6 +20,7 @@ declare module "stream" { } class Readable extends Stream implements NodeJS.ReadableStream { + static from(iterable: Iterable | AsyncIterable, opts?: ReadableOptions): NodeJS.ReadableStream; readable: boolean; readonly readableHighWaterMark: number; readonly readableLength: number; diff --git a/types/node/test/stream.ts b/types/node/test/stream.ts index 892f5a0fca1fa7c..841a286a49abfb9 100644 --- a/types/node/test/stream.ts +++ b/types/node/test/stream.ts @@ -192,3 +192,17 @@ function stream_readable_pipe_test() { z.close(); rs.close(); } + +async function readable_from() { + const list = [ 1, 2, 3 ]; + const listPromise = list.map(n => Promise.resolve(n))); + + const readableSync = Readable.from(list); + const readableAsync = Readable.from(listPromise); + + let i = 0; + readableSync.on('data', n => assert(n === list[i++])); + + let j = 0; + readableAsync.on('data', n => assert(n === list[j++])); +}