A) spreading nullish values should trigger an exception B) nullish values should silently spread to nothing C) nullish values should be treated differently in array spread vs. object spread
-
-
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
C is the current situation
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
modest proposal: null spreads to nothing, but only with a new operator: `{ ...object1, ..?object2 }`
-
For object spread, null and undefined already spread to nothing. Array spread throws instead. Are you suggesting throwing for both spread variants, and then adding a new operator to opt-in to the other behavior?
- 5 more replies
New conversation -
-
-
For me, it has to be A. It's always better to have a engineer deal with exceptions up front and acknowledge their existence. Letting things silently pass through can cause chaos if test coverage isn't up to scratch.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Undefined is silently ignored, null throws? Null is much more of an explicit "nothing" than undefined is, so this feels more reasonable, but I dunno
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Spreading null makes no sense to me in either context and I'd treat both as an error.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
C, given how Object.assign works.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Im close to "skip null but throw if undefined" because `undefined` means unassigned object' filed/var - its definitely logic error. Explicitly assign `null` is ok. Array spread is already hide your logic errors because it explode strings.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
And behavior of array' spread should not differ from `[].concat` (that sad, it does not skip nulls), same for object spread <=> `Object.assign`(skip both `null` and `undefined`)
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.