visx
visx copied to clipboard
`scaleThreshold` has incorrectly strict `domain` typing
For example for a threshold scale of:
const scale = scaleThreshold({
domain: [1, 2, 5, 10],
range: ['a', 'b', 'c', 'd']
})
It will infer a type of:
const scale: ScaleThreshold<1 | 2 | 5 | 10, string, never>
When I believe it should really be more generic:
const scale: ScaleThreshold<number, string, never>
Hi @ianstormtaylor, thanks for reporting.
I was able to reproduce the incorrect inferred type here: https://codesandbox.io/s/competent-sun-0n5r4?file=/src/App.tsx
![](https://user-images.githubusercontent.com/339208/108863615-5f1ef600-75bf-11eb-9ac5-158826372d00.png)
one workaround:
another:
const domain = [1, 2, 5, 10];
const range = ["a", "b", "c", "d"];
![](https://user-images.githubusercontent.com/339208/108864255-056afb80-75c0-11eb-9906-3cfe16a20a02.png)
@kristw do you have any insights into TS failing to infer input type on inlined arguments?
@kristw re-pinging you on this one
I'm not sure about this too. Had the same issue and had to manually specify generic type (what @hshoff did) to overcome.
Note that it only occurs for non-continuous scales. (linear
, log
, ... won't have this problem)
d3
is also not native ts but use type declaration so it could not leave the return type implicit. This sometimes make it too strict and could not rely on increasingly smarter inference.