1

I recently set up a simple TypeScript app using Expo CLI with the command expo init appName using the TypeScript template. The app was functioning well until I tried to integrate the react-native-gifted-charts library to include a bar chart. Unfortunately, I encountered an issue that I'm having trouble resolving.

Here's the code snippet where I attempted to use the BarChart component from react-native-gifted-charts:

import { BarChart } from "react-native-gifted-charts";
...
...

<View style={styles.chartContainer}>
          <BarChart
            data={Data}
            width={300}
            height={200}
            chartConfig={{
              backgroundGradientFrom: "#1E2923",
              backgroundGradientTo: "#08130D",
              fillShadowGradient: "#45E355",
              fillShadowGradientOpacity: 0.8,
              color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
              labelColor: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
              style: {
                borderRadius: 16,
              },
            }}
            style={{
              marginVertical: 8,
              borderRadius: 16,
            }}
          />
        </View>

When I attempt to use the above code, I encounter an error message that points to the NativeModules.js file. However, upon inspecting the NativeModules.js file, I noticed that it appears to contain TypeScript content, even though its file extension is .js. This discrepancy is puzzling to me and is causing several error lines within the file.

I'm unsure if I'm using the BarChart component incorrectly or if there's something else going on. I am seeking clarification on the following points:

How can I correctly integrate and use the react-native-gifted-charts library, specifically the BarChart component, in a TypeScript-based Expo app?

Why is the NativeModules.js file being automatically generated with a .js file extension while containing TypeScript-like content? Are there any suggestions on resolving the issue with the NativeModules.js file and the related errors?

2 Answers 2

0

I am the author and maintainer of react-native-gifted-charts. Your issue has nothing to do with expo, instead the problem was with react-native-gifted-charts. There were some type related issues in the library from the beginning.

Thankfully, type related issues no longer exist in the library from versions 1.4.23 onwards. The current latest version as of today is 1.4.28.

The library earlier exported raw typescript. Now it exports compiled javascript files and type declarations (.d.ts files). This has fixed all the issues related to typescript.

Sign up to request clarification or add additional context in comments.

Comments

-1

You'll need a development build according to the expo doc

1 Comment

Please share the code with some solution you have tried

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.