typescript 属性“center”不存在于传单上的类型“IntrinsicAttributes & MapContainerProps”中

hgb9j2n6  于 2023-03-13  发布在  TypeScript
关注(0)|答案(1)|浏览(152)

我尝试在我的应用上实现一个简单的Map,但在使用下面的React Leaflet示例代码时遇到此错误。

import React from "react";
import { MapContainer, TileLayer, Marker, Popup } from "react-leaflet";

export default function App() {
  return (
    <MapContainer center={[51.505, -0.09]} zoom={13} scrollWheelZoom={false}>
        <TileLayer
            attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
            url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
        />
        <Marker position={[51.505, -0.09]}>
            <Popup>
            A pretty CSS3 popup. <br /> Easily customizable.
            </Popup>
        </Marker>
    </MapContainer>
  );
}

错误:

Type '{ children: Element[]; center: number[]; zoom: number; scrollWheelZoom: boolean; }' is not assignable to type 'IntrinsicAttributes & MapContainerProps'.
  Property 'center' does not exist on type 'IntrinsicAttributes & MapContainerProps'.  TS2322

    150 |                     />
    151 | 
  > 152 | <MapContainer center={[51.505, -0.09]} zoom={13} scrollWheelZoom={false}>
        |               ^
    153 |   <TileLayer
    154 |     attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
    155 |     url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"

我用的是React和Typescript。

ohfgkhjo

ohfgkhjo1#

尝试安装传单类型:

yarn add -D @types/react-leaflet

然后重新启动项目。

相关问题