Hacker News new | past | comments | ask | show | jobs | submit login

Interestingly, JavaScript has the opposite problem: {...null} is fine (returns {}), but [...null] is not (TypeError: Spread syntax requires ...iterable not be null or undefined).



Thanks for making me aware of this. I guess {...something ?? {} } and [...something ?? [] ] are then appropriate to avoid any trouble for now.


This 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.


I was quite surprised by this, I was certain it wasn’t true, but I checked and it is!




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: