Grid组件使用动态动态数据报错
如果为item指定 interface Groups {...} 自己定义的类型,会报不能分配到XXX的错误
TS2769: No overload matches this call. Overload 1 of 2, '(props: GridProps | Readonly<GridProps>): Grid', gave the following error. Type '(item: Groups) => JSX.Element' is not assignable to type '(dataItem: DataItem | undefined, itemIndex: number) => ReactElement<any, string | JSXElementConstructor<any>>'. Types of parameters 'item' and 'dataItem' are incompatible. Type 'DataItem | undefined' is not assignable to type 'Groups'. Type 'undefined' is not assignable to type 'Groups'. Overload 2 of 2, '(props: GridProps, context: any): Grid', gave the following error. Type '(item: Groups) => JSX.Element' is not assignable to type '(dataItem: DataItem | undefined, itemIndex: number) => ReactElement<any, string | JSXElementConstructor<any>>'. PropsType.d.ts(14, 5): The expected type comes from property 'renderItem' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Grid> & Pick<Readonly<GridProps> & Readonly<{ children?: ReactNode; }>, "children" | ... 4 more ... | "renderItem"> & Partial<...> & Partial<...>' PropsType.d.ts(14, 5): The expected type comes from property 'renderItem' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Grid> & Pick<Readonly<GridProps> & Readonly<{ children?: ReactNode; }>, "children" | ... 4 more ... | "renderItem"> & Partial<...> & Partial<...>'
此时说对象可能是undefined
修改antd自带的类型声明文件可以达到效果