react-google-charts
react-google-charts copied to clipboard
Type 'string' is not assignable to type 'GoogleVizEventName'.
I am using React ^16.8.6
with TypeScript 3.8.0-dev.20200109
and react-google-charts ^3.0.15
.
I have followed verbatim the events example Listen to chart events in the README.
I receive the error
Type 'string' is not assignable to type 'GoogleVizEventName'.
and also the error
Type '{ eventName: string; callback(...}' is not assignmable to type 'ReactGoogleChartEvent'.
It is my understanding that react-google-charts now supports TypeScript out-of-the-box, so I'm not sure what is the correct solution for my issue.
It looks like I was able to resolve my issue by importing the ReactGoogleChartEvent
type with
import {ReactGoogleChartEvent} from 'react-google-charts/dist/types'
and then assigning that type to the event object by adding as ReactGoogleChartEvent
to the README example, like so:
const chartEvents = [
{
eventName: "select",
callback({ chartWrapper }) {
console.log("Selected ", chartWrapper.getChart().getSelection());
}
} as ReactGoogleChartEvent,
];
Is this the recommended solution?