-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Hi thanks for this package. I have two TS errors using the Ponyfill.
- does not work with
moduleResolution: "Node"(solvable)
The most common resolution to use but the defs can't be found with it. Solved by changing to:
"module": "NodeNext",
"moduleResolution": "nodenext",
or
"module": "ES2022",
"moduleResolution": "Bundler",
I guess the way defs are compiled is too modern but that's fine, it's solvable.
- incorrect type defs
The current def for asyncIterator.d.ts is:
/**
* the implementer that does all the heavy works
*/
declare class ReadableStreamAsyncIterableIteratorImpl<R, TReturn> implements AsyncIterator<R> {
#private;
constructor(reader: ReadableStreamDefaultReader<R>, preventCancel: boolean);
next(): Promise<IteratorResult<R, undefined>>;
return(value?: TReturn): Promise<IteratorReturnResult<TReturn>>;
}
declare const implementSymbol: unique symbol;
/**
* declare `ReadableStreamAsyncIterableIterator` interaface
*/
interface ReadableStreamAsyncIterableIterator<R, TReturn> extends ReadableStreamAsyncIterator<R> {
[implementSymbol]: ReadableStreamAsyncIterableIteratorImpl<R, TReturn>;
}
export interface ReadableStreamIteratorOptions {
preventCancel?: boolean;
}
/**
* Get an async iterable iterator from a readable stream
* @param readableStream
* @param readableStreamIteratorOptions
* @returns
*/
export declare function asyncIterator<R, TReturn>(readableStream: ReadableStream<R>, { preventCancel }?: ReadableStreamIteratorOptions): ReadableStreamAsyncIterableIterator<R, TReturn>;
export {};This results in:
for await (const chunk of asyncIterator(res.body)) {}Type 'ReadableStreamAsyncIterableIterator<Uint8Array, unknown>' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.ts(2504)
This is because the interface doesn't define an asyncIterator, it has this funny implementSybol instead. Simply doing:
interface ReadableStreamAsyncIterableIterator<R, TReturn> extends ReadableStreamAsyncIterator<R> {
[Symbol.asyncIterator](): ReadableStreamAsyncIterableIteratorImpl<R, TReturn>;
// Or more acceptable by eslint (@typescript-eslint/method-signature-style):
// [Symbol.asyncIterator]: () => ReadableStreamAsyncIterableIteratorImpl<R, TReturn>
}Fixes the issue.
Is there a reason you defined an anonymous symbol that Typescript isn't aware of?:
readable-stream/src/core/asyncIterator.ts
Line 87 in 5802d75
| const implementSymbol = Symbol(); |
mauricedoepke
Metadata
Metadata
Assignees
Labels
No labels