fix(stream): Default types to undefined
MODIFY
packages/stream-types-test/validation.ts
packages/stream-types-test/validation.ts
@@ -59,8 +59,14 @@ async () => {
const f: IteratorResult<string, Array<number>> = await writer.throw(new Error('Abort'));
};
+async () => {
+ const [reader, writer]: [Reader<number>, Writer<number>] = makePipe<number>();
+ const r: Reader<number> = mapReader<number>(reader, (n: number) => n + 1);
+ const w: Writer<number> = mapWriter<number>(writer, (n: number) => n - 1);
+};
+
async () => {
const [reader, writer]: [Stream<number, string>, Stream<string, number>] = makePipe<number, string>();
- const r: Stream<string> = mapReader<number, string>(reader, (n: number) => String.fromCharCode(n));
- const w: Stream<unknown, string> = mapWriter<string, number>(writer, (value: string) => value.charCodeAt(0));
+ const r: Stream<string, string> = mapReader<number, string, string>(reader, (n: number) => String.fromCharCode(n));
+ const w: Stream<string, string> = mapWriter<string, number, string>(writer, (value: string) => value.charCodeAt(0));
};

MODIFY
packages/stream/index.d.ts
packages/stream/index.d.ts
@@ -5,9 +5,9 @@ export function makeQueue<TValue>(): AsyncQueue<TValue>;
export function makeStream<
TRead,
- TWrite = unknown,
- TReadReturn = unknown,
- TWriteReturn = unknown,
+ TWrite = undefined,
+ TReadReturn = undefined,
+ TWriteReturn = undefined,
>(
acks: AsyncQueue<IteratorResult<TRead, TReadReturn>>,
data: AsyncQueue<IteratorResult<TWrite, TWriteReturn>>,
@@ -15,9 +15,9 @@ export function makeStream<
export function makePipe<
TRead,
- TWrite = unknown,
- TReadReturn = unknown,
- TWriteReturn = unknown,
+ TWrite = undefined,
+ TReadReturn = undefined,
+ TWriteReturn = undefined,
>(): [
Stream<TRead, TWrite, TReadReturn, TWriteReturn>,
Stream<TWrite, TRead, TWriteReturn, TReadReturn>,
@@ -25,10 +25,10 @@ export function makePipe<
export function mapReader<
TReadIn,
- TReadOut,
- TReadReturn = unknown,
- TWrite = unknown,
- TWriteReturn = unknown,
+ TReadOut = TReadIn,
+ TWrite = undefined,
+ TReadReturn = undefined,
+ TWriteReturn = undefined,
>(
reader: Stream<TReadIn, TWrite, TReadReturn, TWriteReturn>,
transform: (value: TReadIn) => TReadOut,
@@ -36,10 +36,10 @@ export function mapReader<
export function mapWriter<
TWriteIn,
- TWriteOut,
- TWriteReturn = unknown,
- TRead = unknown,
- TReadReturn = unknown,
+ TWriteOut = TWriteIn,
+ TRead = undefined,
+ TReadReturn = undefined,
+ TWriteReturn = undefined,
>(
writer: Stream<TRead, TWriteOut, TReadReturn, TWriteReturn>,
transform: (value: TWriteIn) => TWriteOut,

MODIFY
packages/stream/types.d.ts
packages/stream/types.d.ts
@@ -9,9 +9,9 @@ export interface AsyncQueue<TValue> {
// types.
export interface Stream<
TRead,
-TWrite = unknown,
-TReadReturn = unknown,
-TWriteReturn = unknown,
+ TWrite = undefined,
+ TReadReturn = undefined,
+ TWriteReturn = undefined,
> {
next(value: TWrite): Promise<IteratorResult<TRead, TReadReturn>>,
return(value: TWriteReturn): Promise<IteratorResult<TRead, TReadReturn>>,
@@ -19,5 +19,5 @@ TWriteReturn = unknown,
[Symbol.asyncIterator](): Stream<TRead, TWrite, TReadReturn, TWriteReturn>,
}
-export type Reader<TRead, TReadReturn = undefined> = Stream<TRead, unknown, TReadReturn, unknown>;
-export type Writer<TWrite, TWriteReturn = undefined> = Stream<unknown, TWrite, unknown, TWriteReturn>;
+export type Reader<TRead, TReadReturn = undefined> = Stream<TRead, undefined, TReadReturn, undefined>;
+export type Writer<TWrite, TWriteReturn = undefined> = Stream<undefined, TWrite, undefined, TWriteReturn>;

fix(stream): Default types to undefined