What does it mean that the Generic Type <T> 'function requires 1 type argument in Typescript?
I am trying to use GeoJson in typescript, but the compiler throws an error for these 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 does this mean?
+6
1 answer
The function interface requires a parameter:
export interface Feature<T extends GeometryObject> extends GeoJsonObject { geometry: T; properties: any; id?: string; } Try the following:
const pos = <GeoJSON.Feature<GeoJSON.GeometryObject>>{ "type": "Feature", "properties":{}, "geometry": { "type": "Point", "coordinates": [0, 1] } }; And perhaps enter a helper type and set the type in pos instead of casting, which will help you set the required attribute of the properties:
type GeoGeom = GeoJSON.Feature<GeoJSON.GeometryObject>; const pos: GeoGeom = { type: "Feature", properties: "foo", geometry: { type: "Point", coordinates: [0, 1] } }; +3