Friday, 14 July 2023

D3 .extent() rejecting array of Dates in typescript

I'm struggling to utilize d3's .extent() function in typescript.

I've got some code here that creates Date objects out of dates

 const dates:(Date | null)[] = data.map(row => d3.timeParse("%Y-%m-%d")(row.Date))

When I console log the dates variable, it looks something like this

[Sat Jun 24 2023 00:00:00 GMT-0700 (Pacific Daylight Time), Sat Jun 24 2023 00:00:00 GMT-0700 (Pacific Daylight Time), Fri Jun 23 2023 00:00:00 GMT-0700 (Pacific Daylight Time), Fri Jun 23 2023 00:00:00 GMT-0700 (Pacific Daylight Time), Fri Jun 23 2023 00:00:00 GMT-0700 (Pacific Daylight Time), ...]

Therefore, I know my dates variable is full of Date objects, like expected...

However, when I try and use the d3.extent() function to find the highest and lowest dates

const xScale = d3
      .scaleTime()
      .domain(d3.extent(dates))
Argument of type '[undefined, undefined] | [string, string]' is not assignable to parameter of type 'Iterable<Date | NumberValue>'.

I'm confused as to why this might be, though, as my dates variable is in fact exclusively dates, and not, as is expressed in the error, '[undefined, undefined] | [string, string]'.

What is wrong about what I am passing in? How should I be passing in dates to the extent() function in typescript?



from D3 .extent() rejecting array of Dates in typescript

No comments:

Post a Comment