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

Closed
benlesh opened this issue Mar 5, 2024 · 5 comments
Closed

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

benlesh opened this issue Mar 5, 2024 · 5 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
Contributor

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)

@domfarolino
Copy link
Collaborator

I'm sold on ensuring Observable.from("string") works the same as Observable.from(Object("string")) does today, by basically adding special handling like https://github.com/tc39/proposal-iterator-helpers/pull/250/files did for Iterator helpers. I'll ensure that this makes it into #160, and I'll close this issue.

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

6 participants