observable
observable copied to clipboard
Observable.from should throw primitive iterables (strings)
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
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 https://github.com/tc39/proposal-iterator-helpers/issues/244.
FYI: ReadableStream.from
rejects string
https://github.com/whatwg/webidl/pull/1397
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.