首页 > 解决方案 > 将图标添加到项目材料表错误

问题描述

我正在尝试执行此操作https://github.com/mbrn/material-table但出现错误。我认为有问题是因为我使用的是 TSX 而不是 JSX?你知道怎么修吗?

在此处输入图像描述

No overload matches this call.
  Overload 1 of 2, '(props: { component: ElementType<any>; } & { children?: ReactNode; color?: "primary" | "secondary" | "disabled" | "error" | "inherit" | "action" | undefined; fontSize?: "inherit" | ... 3 more ... | undefined; htmlColor?: string | undefined; shapeRendering?: string | undefined; titleAccess?: string | undefined; viewBox?: string | undefined; } & CommonProps<...> & Pick<...>): Element', gave the following error.
    Property 'component' is missing in type '{ ref: ((instance: unknown) => void) | MutableRefObject<unknown> | null; children?: ReactNode; }' but required in type '{ component: ElementType<any>; }'.
  Overload 2 of 2, '(props: DefaultComponentProps<SvgIconTypeMap<{}, "svg">>): Element', gave the following error.
    Type '((instance: unknown) => void) | MutableRefObject<unknown> | null' is not assignable to type '((instance: SVGSVGElement | null) => void) | RefObject<SVGSVGElement> | null | undefined'.
      Type 'MutableRefObject<unknown>' is not assignable to type '((instance: SVGSVGElement | null) => void) | RefObject<SVGSVGElement> | null | undefined'.
        Type 'MutableRefObject<unknown>' is not assignable to type 'RefObject<SVGSVGElement>'.ts(2769)
OverridableComponent.d.ts(17, 7): 'component' is declared here.

和这里

在此处输入图像描述

No overload matches this call.
  Overload 1 of 2, '(props: Readonly<MaterialTableProps<{ name: string; surname: string; birthYear: number; birthCity: number; }>>): MaterialTable<{ name: string; surname: string; birthYear: number; birthCity: number; }>', gave the following error.
    Type '{ Add: React.ForwardRefExoticComponent<React.RefAttributes<unknown>>; Check: React.ForwardRefExoticComponent<React.RefAttributes<unknown>>; Clear: React.ForwardRefExoticComponent<React.RefAttributes<unknown>>; ... 13 more ...; ViewColumn: React.ForwardRefExoticComponent<...>; }' is not assignable to type 'Icons'.
      The types of 'Add.defaultProps' are incompatible between these types.
        Type 'Partial<RefAttributes<unknown>> | undefined' is not assignable to type 'Partial<RefAttributes<SVGSVGElement>> | undefined'.
          Type 'Partial<RefAttributes<unknown>>' is not assignable to type 'Partial<RefAttributes<SVGSVGElement>>'.
            Types of property 'ref' are incompatible.
              Type '((instance: unknown) => void) | RefObject<unknown> | null | undefined' is not assignable to type '((instance: SVGSVGElement | null) => void) | RefObject<SVGSVGElement> | null | undefined'.

标签: node.jsreactjsmaterial-uimaterial-table

解决方案


尝试这个

forwardRef<SVGSVGElement>

在图标中或

像这样导入图标:

import MaterialTable, { Icons } from 'material-table'
const tableIcons: Icons = {...}

推荐阅读