d3 / d3-scale

Encodings that map abstract data to visual representation.

Home Page:https://d3js.org/d3-scale

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support string 'rgba' values in signature of scaleLinear().range()

brianrodri opened this issue · comments

The signature of d3.scaleLinear().range does not accept string arrays as arguments, resulting in compile-time errors.

Observed behavior
The code:

const color = d3.scaleLinear()
  .domain([0, d3.max(bins, d => d.length)])
  .range(['rgba(255,255,255,0.5)', 'rgba(255,255,255,1.0)']);

...results in the following compile-time TypeScript error:

error TS2345: Argument of type 'string[]' is not assignable to parameter of type 'readonly number[]'.

Type 'string' is not assignable to type 'number'.

Expected behavior
No compile-time error, given that rgba strings are supported by the function.

It looks like you want to file an issue with D3’s TypeScript bindings, which I don’t maintain. Maybe you meant to file this in the DefinitelyTyped repo? Works for me…

https://observablehq.com/d/cab0fd1ade184637