sindresorhus / globby

User-friendly glob matching
MIT License
2.53k stars 130 forks source link

Typings: why does `for await` produce `string | Buffer` instead of `string`? #144

Open papb opened 4 years ago

papb commented 4 years ago

Directly from the example from readme:

(async () => {
    for await (const path of globby.stream('*.tmp')) {
        console.log(path); // TypeScript says `path` is `string | Buffer`
    }
})();

Shouldn't path be just a string?

sindresorhus commented 4 years ago

It just returns a NodeJS.ReadableStream type. A stream chunk could be either a string or buffer. There must be a way to specialize it.

papb commented 4 years ago

@sindresorhus I see, but just to make sure: in this case, it should indeed return just a string, right? Or is there any real situation in which globby.stream can generate Buffer chunks?

In other words, is this just a matter of improving typings, or is it more complex?

sindresorhus commented 4 years ago

In other words, is this just a matter of improving typings, or is it more complex?

The typings.