3 ms·
Interestingly, JavaScript has the opposite problem: {...null} is fine (returns {}), but [...null] is not (TypeError: Spread syntax requires ...iterable not be n
by pzmarzly 2y ago
Interestingly, JavaScript has the opposite problem: {...null} is fine (returns {}), but [...null] is not (TypeError: Spread syntax requires ...iterable not be null or undefined).
- fwlr 2y agoI was quite surprised by this, I was certain it wasn’t true, but I checked and it is!
- kevincox 2y agoThis tricks me all of the time. Part of me wants for it to work to avoid allocating an empty array object in situations like `[...opts?.foo.map(format)]`. On the other hand I appreciate the stricter type safety.
- psychoslave 2y agoThanks for making me aware of this. I guess {...something ?? {} } and [...something ?? [] ] are then appropriate to avoid any trouble for now.