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

Observable.from should throw primitive iterables (strings) #125

Open
benlesh opened this issue Mar 5, 2024 · 4 comments
Open

Observable.from should throw primitive iterables (strings) #125

benlesh opened this issue Mar 5, 2024 · 4 comments

Comments

@benlesh
Copy link
Collaborator

benlesh commented Mar 5, 2024

Along with how Iterator helpers behave, if a user passes a string, even though it's an iterable, it's likely an error. We should throw a TypeError in that case.

Observable.from('some string'); // TypeError
@bakkot
Copy link
Contributor

bakkot commented Mar 5, 2024

I think you misread my comment (which was not all that clear, sorry). Iterator.from does not throw when given a string. This makes it different from flatMap, which does throw when the mapper returns a string, even though strings are iterable.

See discussion in tc39/proposal-iterator-helpers#244.

@petamoriken
Copy link

FYI: ReadableStream.from rejects string whatwg/webidl#1397

@ljharb
Copy link

ljharb commented Aug 17, 2024

If someone is intentionally passing a string into an X.from method, they explicitly want to convert a string into an X. I think this is the one case where an iterable string must be accepted.

@flensrocker
Copy link

Can a usecase be returning a string from the catch operator?
How should I do this if Observable.from throws on a string? Or can I just return the string?
(having rxjs of("...") in mind)

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

No branches or pull requests

5 participants