mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
Iterable<T> maps to a union of the sources that keep their own representation (T[], Set<T>, Map<K, V> for [K, V] entries, string) and a generator over T that holds every iterator. An array stays the same multi-pass object; a generator stays single-pass. for-of gives the array arm its own array loop, so iterating an Iterable that holds an array runs at array speed. Spread, Array.from, the Set/Map constructors and Object.fromEntries consume it; optional Iterables narrow into it; generator functions may declare an Iterable return. Class iterables and typed arrays are refused at the conversion with a named diagnostic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 lines
339 B
Plaintext
3 lines
339 B
Plaintext
- **Iterable values:** A value typed `Iterable<T>` can hold an array, a Set, a Map (for `Iterable<[K, V]>`), a string (for `Iterable<string>`), a generator, or a Map, Set or array iterator.
|
|
Class instances with their own `[Symbol.iterator]` method and typed arrays can't be stored in an `Iterable<T>` and are reported at the conversion.
|