Typescript和react-google-maps元素不可分配为“从不”类型

问题描述

等等,我找到了解决方案! WrappedMap只需要输入任何一个即可。

我是TypeScript的初学者。我目前正在研究“ react-google-maps” 错误消息(元素不可分配为“从不”类型)带有四个元素:containerElement,mapElement,googleMapURL和loadingElement。

有人有什么主意吗?

import React from "react";
import {withScriptjs,withGoogleMap,GoogleMap} from "react-google-maps";



export default function GoogleMapsPage() {
    function Map() {
        return (
            <GoogleMap
                defaultZoom={10}
                defaultCenter={{lat: 48.13909,lng: 22.58030}}>
            </GoogleMap>
        )
    }

    //const WrappedMap = withScriptjs(withGoogleMap(Map));
    const WrappedMap: any = withScriptjs(withGoogleMap(Map));  //this works.


    return (
            <div style={{width: '100vw',height: '100vh'}}>

                <WrappedMap
                    containerElement={<div style={{height: `400px`}}/>}
                    mapElement={<div style={{height: `100%`}}/>}
                    googleMapURL={`https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,drawing,places&key=${process.env.REACT_APP_GOOGLE_MAPS_API_KEY}`}
                    loadingElement={<div style={{height: `100%`}}/>}>
                </WrappedMap>


            </div>
    )
}



解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)