Skip to content

TextDecoder pollyfill improvement and TypeScript declaration fix for DirHandle#321

Merged
saghul merged 2 commits intosaghul:masterfrom
samuelbrian:fixes0
Nov 4, 2022
Merged

TextDecoder pollyfill improvement and TypeScript declaration fix for DirHandle#321
saghul merged 2 commits intosaghul:masterfrom
samuelbrian:fixes0

Conversation

@samuelbrian
Copy link
Copy Markdown
Contributor

Sorry I missed your release with these @saghul.

…. of'

When using the docs TypeScript declaration file, the example async iterator
code...

    const dirIter = await tjs.readdir('.');
    for await (const item of dirIter) {
        console.log(item.name);
    }

...does not compile due to a TypeScript error.

    error TS2504: Type 'DirHandle' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.

The DirHandle must be declared as an AsyncIterableIterator, which the
implementation already satisfies, instead of an AsyncIterator.

The MDN reference on `for await ... of` hints at the need for this:

    Note: for await...of doesn't work with async iterators that are not async iterables.
The UTF-8-only encoder/decoder was performing poorly due to inefficient
array manipulation.
Applied changes from the original text-encoding package that reduce
the amount of copying.

Relates to saghul#316
@saghul
Copy link
Copy Markdown
Owner

saghul commented Nov 4, 2022

Sorry I missed your release with these @saghul.

No worries, numbers are cheap! 😅

@saghul saghul merged commit ef2f563 into saghul:master Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants