Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[d3-scale] Can't pass string range to linear scale #72

Closed
rybaczewa opened this issue Jun 28, 2017 · 3 comments
Closed

[d3-scale] Can't pass string range to linear scale #72

rybaczewa opened this issue Jun 28, 2017 · 3 comments

Comments

@rybaczewa
Copy link

Passing string range to scaleLinear like so:

import * as d3Scale from 'd3-scale';

d3Scale.scaleLinear()
  .domain([1, 20])
  .clamp(true)
  .range(['#fff', '#000']);

Argument of type 'string[]' is not assignable to parameter of type 'number[]'.

As seen here, this should be possible:

Unlike the domain, elements in the given array need not be numbers; any value that is supported by the underlying interpolator will work

@tomwanzek
Copy link
Owner

scaleLinear() as a scale factory and the corresponding interface ScaleLinear are parameterized with two generics (Range and Output). By default, i.e. scaleLinear(), these default to number.

To set another type for the range (and or scale output), please use scaleLinear<string>() or similar. The JSDoc comments for the linear scale generator explain the usage for each of the signatures.

The service works as intended. 😄

@rybaczewa
Copy link
Author

rybaczewa commented Jun 29, 2017

My bad then, I misunderstood the function comments. Thanks for help.

@tomwanzek
Copy link
Owner

No worries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants