Open digital-nomad17 opened 6 years ago
To eliminate this error, try to explicitly specify map component properties.
For that matter the following type could be introduced:
type MapProps = {
children?: React.ReactNode,
directions: google.maps.DirectionsResult
};
then a map component defined like this:
const Map = (props: MapProps) => {
return (
<GoogleMap
defaultZoom={7}
defaultCenter={new google.maps.LatLng(41.8507300, -87.6512600)}
>
{props.directions && <DirectionsRenderer directions={props.directions} />}
</GoogleMap>
);
}
and
const MapWithADirectionsRenderer = compose(
withProps({
containerElement: <div style={{ height: `400px` }} />,
googleMapURL: "https://maps.googleapis.com/maps/api/js?key=AIzaSyC4R6AN7SmujjPUIGKdyao2Kqitzr1kiRg&v=3.exp&libraries=geometry,drawing,places",
loadingElement: <div style={{ height: `100%` }} />,
mapElement: <div style={{ height: `100%` }} />,
}),
withScriptjs,
withGoogleMap,
lifecycle({
componentDidMount() {
const DirectionsService = new google.maps.DirectionsService();
DirectionsService.route({
destination: new google.maps.LatLng(41.8525800, -87.6514100),
origin: new google.maps.LatLng(41.8507300, -87.6512600),
travelMode: google.maps.TravelMode.DRIVING,
}, (result, status) => {
if (status === google.maps.DirectionsStatus.OK) {
this.setState({
directions: result,
});
} else {
console.log(`error fetching directions ${result}`);
}
});
}
})
)(Map);
Argument of type '(props: MapProps) => Element' is not assignable to parameter of type 'ComponentType
Getting Help
Hi,
I am using the typescript definitions and I am running into this error:
I copied the code(except the import statements) from the DirectionsRenderer example to test it out. Here is the code:
It looks like the property isn't defined in the typescript file.
Here's my dependency versions for the record:
@mxl You might have a better idea of this typescript issue.