d3 / d3-selection

Transform the DOM by selecting elements and joining to data.
https://d3js.org/d3-selection
ISC License
558 stars 292 forks source link

Raise an error when passing a `selection.data()` key that does not evaluate to a string. #293

Closed mjmdavis closed 3 years ago

mjmdavis commented 3 years ago

As a naive user, I've fallen into the trap of passing an object a few times and d3 doesn't complain and 'kind of' works but the behaviour is not what I intended.

Adding a check might save some people similar confusion.

mbostock commented 3 years ago

Values are coerced to a string (e.g., dates), so it would be far too strict to throw an error for all objects. We could specifically test for “[object Object]”, but I think that would be overly precise and also prone to false positives.