【发布时间】:2020-04-28 14:07:32
【问题描述】:
我正在使用@types/react-simple-maps,并在他们的一个类型定义中:
interface GeographiesChildrenArgument {
geographies: object[];
path: GeoPath;
projection: GeoProjection;
}
他们使用object[]
现在,当我尝试使用这些定义时,我必须这样做:
{({ geographies }): React.ReactNodeArray => geographies.map(
(geo: object) => (
...
有没有办法让对象更具体?如果我尝试:
{({ geographies }: { geographies: GeographyType[] }): React.ReactNodeArray => geographies.map(
(geo: GeographyType) => (
...
然后我收到以下错误:
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; }'
那么,有没有办法覆盖object[] 成为我的对象定义:GeographyType[]?
【问题讨论】:
标签: javascript reactjs typescript