Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
papb opened this issue Jun 1, 2020 · 3 comments
Open

Comments

@papb
Copy link

papb commented Jun 1, 2020

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
Copy link
Owner

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
Copy link
Author

papb commented Jun 2, 2020

@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
Copy link
Owner

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

The typings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants