【发布时间】:2018-12-27 19:33:06
【问题描述】:
我是 Typescript 的初学者,很困惑。我有一个使用 react-google-maps 的组件,该组件是可重用的。
Map.tsx
import * as React from 'react';
import { compose, withStateHandlers } from 'recompose';
import { GoogleMap, withGoogleMap } from 'react-google-maps';
const ContactMap: React.ComponentClass<{}> = compose(
withStateHandlers(() => ({
isOpen: false,
// tslint:disable-next-line:align
}), {
onToggleOpen: ({ isOpen }) => () => ({
isOpen: !isOpen,
}),
}),
withGoogleMap,
)(props =>
<div>
<GoogleMap
defaultZoom={props.zoom}
defaultCenter={props.center}
defaultOptions={{
streetViewControl: false,
scaleControl: false,
mapTypeControl: false,
panControl: false,
zoomControl: false,
rotateControl: false,
fullscreenControl: false,
disableDefaultUI: true,
scrollwheel: false,
}}
>
{props.children}
</GoogleMap>,
</div>,
);
export default ContactMap;
错误是:Property 'zoom' does not exist on type '{ children?: ReactNode; }'.,我认为它会为 center 做同样的事情。
我尝试过类似的东西
interface Props {
containerElement: any;
mapElement: any;
zoom: number;
center: any;
}
然后将其传入,但这并不能解决问题。它返回
Type 'ComponentClass<{}>' is not assignable to type 'ComponentClass<Props>'.
Type '{}' is not assignable to type 'Props'.
Property 'containerElement' is missing in type '{}'.
我使用地图的组件:
import * as React from 'react';
import { Map } from '@ecomm/map';
import { InfoWindow, Marker } from 'react-google-maps';
const ContactMap: React.SFC = () => {
return (
<Map
containerElement={<div style={{ height: `400px` }} />}
mapElement={<div style={{ height: `100%` }} />}
center={{
lat: 40.745093,
lng: -73.993048,
}}
zoom={16}
>
<Marker
position={{
lat: 40.745093,
lng: -73.993048,
}}
>
<InfoWindow>
<TextHeader>CHELSEA STUDIO</TextHeader>
</InfoWindow>
</Marker>
</Map>
);
};
export default ContactMap;
我不确定要离开这里,这很令人沮丧。任何帮助,将不胜感激。谢谢。
【问题讨论】:
标签: reactjs typescript react-google-maps