1

I am using @types/react-simple-maps, and in one of their type definitions:

interface GeographiesChildrenArgument {
    geographies: object[];
    path: GeoPath;
    projection: GeoProjection;
}

they use object[]

Now, when I try to use these definitions, I have to do something like this:

{({ geographies }): React.ReactNodeArray => geographies.map(
  (geo: object) => (
    ...

is there a way I could make object more specific? If I try:

{({ geographies }: { geographies: GeographyType[] }): React.ReactNodeArray => geographies.map(
  (geo: GeographyType) => (
    ...

but then I get the following error:

Type '({ geographies }: { geographies: GeographyType[]; }) => React.ReactNodeArray' is not assignable to type '((data: GeographiesChildrenArgument) => void) | (((data: GeographiesChildrenArgument) => void) & string) | (((data: GeographiesChildrenArgument) => void) & number) | ... 5 more ... | undefined'.
Type '({ geographies }: { geographies: GeographyType[]; }) => React.ReactNodeArray' is not assignable to type '(data: GeographiesChildrenArgument) => void'.
Types of parameters '__0' and 'data' are incompatible.
Type 'GeographiesChildrenArgument' is not assignable to type '{ geographies: GeographyType[]; }'.
Types of property 'geographies' are incompatible.
Type 'object[]' is not assignable to type 'GeographyType[]'.
Type '{}' is missing the following properties from type 'GeographyType': type, geometry, propertiests (2322)
index.d.ts(95, 5): The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & GeographiesProps & { children?: ReactNode; }'

So, is there a way to override object[] to be my object definition: GeographyType[]?

Ken Bigler
  • 587
  • 1
  • 4
  • 15
  • full code is available here: https://github.com/kennethbigler/react-home/blob/master/src/components/resume/travel-map/WorldMap.tsx – Ken Bigler Jan 10 '20 at 22:44

2 Answers2

1

I would try to extend interface. You can't change the type of existing property. Something like this below. Let me know if it works. Also check this out it's about modifying existing types Overriding interface property type defined in Typescript d.ts file

 {({ geographies }: { geographies: object[] extends GeographyType[] }): React.ReactNodeArray => 
  geographies.map(
   (geo: GeographyType) => (
  ...
Adi
  • 164
  • 1
  • 11
  • I tried that one, you get this error if you try that: ```Type '({ geographies }: { geographies: any; }) => React.ReactNodeArray' is not assignable to type '(geographies: object[], projection: GeoProjection) => void'.``` – Ken Bigler Jan 12 '20 at 15:58
0

This is a silly answer, but the final solution was that I just contributed to @types/react-simple-maps changing object to any as it is recommended in their guidelines to use any over object as object is too restrictive.

Ken Bigler
  • 587
  • 1
  • 4
  • 15