Skip to content

fix: cast xScale.invert result to number in useSpatialIndex#17

Merged
lewisjared merged 1 commit intoClimate-REF:mainfrom
ACCESS-NRI:access-nri
Mar 30, 2026
Merged

fix: cast xScale.invert result to number in useSpatialIndex#17
lewisjared merged 1 commit intoClimate-REF:mainfrom
ACCESS-NRI:access-nri

Conversation

@rbeucher
Copy link
Copy Markdown
Contributor

Hi @lewisjared

I am getting this error when trying to build the docker image:

TYPESCRIPT BUILD ERROR IN USESPATIALINDEX.TS
0.141 > frontend@0.0.0 build
0.141 > tsc -b && vite build
0.141
4.476 src/components/execution/values/series/useSpatialIndex.ts(160,35): error TS2363: The right-hand side [+] up 0/1hmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
⠏ Image local/ref-app:latest Building 11.9s
Dockerfile:39

The issue is that xScale.invert() returns number | Date (since XScaleType is ScaleLinear | ScaleTime), so the arithmetic fails. The fix is to cast it to number.

      // Find the closest data index by X pixel position
      const xVal = xScale.invert(pixelX) as number;

ScaleTime.invert() returns Date while ScaleLinear.invert() returns a number, making xVal typed as number | Date. The cast to number is safe here since the spatial index only works with numeric chart data.

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 27, 2026

👷 Deploy request for climate-ref pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit dbffdd6

@lewisjared lewisjared merged commit 75cc455 into Climate-REF:main Mar 30, 2026
3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants