I try to use GeoJson in typescript but the compiler throws error for this two variables: Generic type 'Feature<T>' requires 1 type argument(s)
const pos = <GeoJSON.Feature>{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [0, 1]
}
};
const oldPos = <GeoJSON.Feature>{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [2, 4]
}
};
What is this supposed to mean?
The Feature interface requires a parameter:
export interface Feature<T extends GeometryObject> extends GeoJsonObject
{
geometry: T;
properties: any;
id?: string;
}
Try this:
const pos = <GeoJSON.Feature<GeoJSON.GeometryObject>>{
"type": "Feature",
"properties":{},
"geometry": {
"type": "Point",
"coordinates": [0, 1]
}
};
And maybe introduce a helper type and set the type on pos instead of casting will help you ensure you've set the required 'properties' attribute:
type GeoGeom = GeoJSON.Feature<GeoJSON.GeometryObject>;
const pos: GeoGeom = {
type: "Feature",
properties: "foo",
geometry: {
type: "Point",
coordinates: [0, 1]
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With