palerdot/react-d3-speedometer

Cannot read property 'Inside' of undefined

Closed this issue ยท 6 comments

react-d3-speedometer version: 0.12.0
react version: 16.13.1
typescript: 3.7.2

Question

I was trying to implement react-d3-speedometer using typescript.
When I tried to apply position in customSegmentLabels , I get an error Type '"OUTSIDE"' is not assignable to type 'CustomSegmentLabelPosition'. So I added it to imports but when I assigned it to position like this:
position: CustomSegmentLabelPosition.Inside, then the error Cannot read property 'Inside' of undefined.

Sample Codesandbox
Sample

@fmsthird

Can your try casting the value? like

          {
            text: "Very Good",
            position: "INSIDE" as CustomSegmentLabelPosition,
            color: "#555"
          }

I agree this should work the way you tried. But for some reason, string enum is not available during run time. I will dig into this when I have time and update here.

Meanwhile, please try casting the string ("INSIDE" as CustomSegmentLabelPosition,) to unblock yourself for now.

Sample sandbox for casting reference

Hi @palerdot

That works! Thank you ๐Ÿ‘
Also, it would be nice in the next update if the text will curve alongside with the bar. ๐Ÿ™‚

Hi,

I'm reopening this issue to keep track of this behavior. The right behavior is to do CustomSegmentLabelPosition.Inside / CustomSegmentLabelPosition.Outside ...

Also regarding

Also, it would be nice in the next update if the text will curve alongside with the bar.

I'm tracking this here - #82

This issue is fixed in v0.13.0

There is proper Typescript enum support for CustomLabelSegmentPosition and Transition. This helper type/Object works both for Typescript and JS.

Typescript Sandbox Example
JS Sandbox Example

./node_modules/we/lib/helpers.js:6:0
Module not found: Can't resolve 'fs'

Import trace for requested module:
./node_modules/we/bin/we
./pages/SpedoMeter.jsx

https://nextjs.org/docs/messages/module-not-found
Screenshot from 2023-06-05 18-49-40