react+typescript 项目中使用antd-mobile-grid报错

Grid组件使用动态动态数据报错

如果为item指定 interface Groups {...} 自己定义的类型,会报不能分配到XXX的错误
image.png

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<...>'

image.png此时说对象可能是undefined

image.png
修改antd自带的类型声明文件可以达到效果


请问此处ts代码该如何写

阅读 2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题