WICG / observable

Observable API proposal
https://wicg.github.io/observable/
Other
575 stars 14 forks source link

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

Open benlesh opened 7 months ago

benlesh commented 7 months ago

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 commented 7 months ago

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.

petamoriken commented 1 month ago

FYI: ReadableStream.from rejects string https://github.com/whatwg/webidl/pull/1397

ljharb commented 1 month ago

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.