-
-
Notifications
You must be signed in to change notification settings - Fork 11
typed streams
Eugene Lazutkin edited this page Jan 18, 2025
·
1 revision
typed-streams
is a collection of typed stream wrappers to simplify using stream-chain
with TypeScript. They allow to specify the type of the input and output streams.
Four classes are exported:
-
TypedReadable<R>
extends Readable. -
TypedWritable<W>
extends Writable. -
TypedDuplex<W, R>
extends Duplex. -
TypedTransform<W, R>
extends Transform.
In all those classes R
means a type that can be read from a stream, and W
means a type that can be written to a stream.
Examples:
import chain from 'stream-chain';
import {TypedTransform} from 'stream-chain/typed-streams.js';
const a = new Transform({
objectMode: true,
transform(x, _, callback) {
callback(null, String(x + 1));
}
}),
b = new TypedTransform<number, string>({
objectMode: true,
transform(x, _, callback) {
callback(null, String(x + 1));
}
});
const pipeline1 = chain([a] as const); // Chain<any, any>
const pipeline2 = chain([b] as const); // Chain<number, string>
const pipeline3 = chain([a as TypedTransform<number, string>] as const); // Chain<number, string>