I'm trying to create a <GeoJSON {...} /> react element from a Feature in Typescript, without success. (I'm using react-leaflet + Typescript) With regular js, I just have to do something like that:
<Map
{...}
<GeoJSON
data={...} <- Here I put my feature in JSON format
style={...} <- Associated style
/>
/>
But in Typescript, if I try to do the exact same thing, I encounter the following error:
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 'GeoJsonObject'.
Overload 2 of 2, '(props: GeoJSONProps, context?: any): 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 'GeoJsonObject'.ts(2769)
Here is a sample of the many things I tried:
<Map
{...}
<GeoJSON
data={{
type: "Feature",
geometry: {
type: "Point",
coordinates: [125.6, 10.1]
}
}}
/>
/>
When I check the GeoJsonObject type definition, geometry does not exists, there is just the "type" field, so how am I supposed to pass the geometry to the GeoJSON element I'm trying to create ? (type definition of GeoJsonObject: http://definitelytyped.org/docs/geojson--geojson/interfaces/geojson.geojsonobject.html )
And if I try this code in "regular" javascript, it does work, do you know why ?