小编Hol*_*ing的帖子

如何使用 Typescript + React-leaflet 创建 GeoJSON 要素元素

我正在尝试从 Typescript 中的功能创建 <GeoJSON {...} /> 反应元素,但没有成功。(我正在使用react-leaflet + Typescript)使用常规js,我只需要做类似的事情:

<Map
    {...}
    <GeoJSON 
        data={...} <- Here I put my feature in JSON format
        style={...} <- Associated style
     />
/>
Run Code Online (Sandbox Code Playgroud)

但在 Typescript 中,如果我尝试执行完全相同的操作,则会遇到以下错误:

No overload matches this call.
  Overload 1 of 2, '(props: Readonly<GeoJSONProps>): GeoJSON<GeoJSONProps, GeoJSON<any>>', gave the following error.
    Type '{ type: string; geometry: { type: string; coordinates: number[]; }; }' is not assignable to type 'GeoJsonObject'.
      Object literal may only specify known properties, and 'geometry' does not exist in type …
Run Code Online (Sandbox Code Playgroud)

javascript leaflet typescript react-leaflet

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

javascript ×1

leaflet ×1

react-leaflet ×1

typescript ×1