Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs react material table with typescript显示一般类型错误_Reactjs_Typescript_Material Ui_Material Table - Fatal编程技术网

Reactjs react material table with typescript显示一般类型错误

Reactjs react material table with typescript显示一般类型错误,reactjs,typescript,material-ui,material-table,Reactjs,Typescript,Material Ui,Material Table,我正在尝试运行一个Typescript项目 因为我是Typescript的新手,所以我遇到了一些错误,我不知道如何解决它们 在本文中,我试图创建一个可重用的React组件。(请打开客人查看完整代码) 正如我所说,上面的示例显示了一些错误,这是主页第48行中的一个示例: No overload matches this call. Overload 1 of 2, '(props: Readonly<MaterialTableProps<IData>>): KTable

我正在尝试运行一个Typescript项目

因为我是Typescript的新手,所以我遇到了一些错误,我不知道如何解决它们

在本文中,我试图创建一个可重用的React组件。(请打开客人查看完整代码)

正如我所说,上面的示例显示了一些错误,这是主页第48行中的一个示例:

No overload matches this call.
  Overload 1 of 2, '(props: Readonly<MaterialTableProps<IData>>): KTable<IData>', gave the following error.
    Type '{ title: string; field: string; type: string; }[]' is not assignable to type 'Column<IData>[]'.
      Type '{ title: string; field: string; type: string; }' is not assignable to type 'Column<IData>'.
        Types of property 'type' are incompatible.
          Type 'string' is not assignable to type '"string" | "boolean" | "time" | "numeric" | "date" | "datetime" | "currency" | undefined'.
  Overload 2 of 2, '(props: MaterialTableProps<IData>, context?: any): KTable<IData>', gave the following error.
    Type '{ title: string; field: string; type: string; }[]' is not assignable to type 'Column<IData>[]'.ts(2769)
尽管接口明确定义了类型accept string:

type?: ('string' | 'boolean' | 'numeric' | 'date' | 'datetime' | 'time' | 'currency');

如果有人知道如何完成这项工作,那会很有帮助。

解决了!我的天啊,我花了这么多时间来处理这个打字错误

type IType =
  | "string"
  | "boolean"
  | "numeric"
  | "date"
  | "datetime"
  | "time"
  | "currency";
const string: IType = "string";

const columns = [
  {
    title: "Name",
    field: "name",
    type: string
  },
  {
    title: "Surname",
    field: "surname",
    type: string
  },
  {
    title: "Birth Year",
    field: "birthYear",
    type: string
  },
  {
    title: "Birth Place",
    field: "birthCity",
    // lookup: { 34: "İstanbul", 63: "Şanlıurfa", 1: "Berlin", 2: "Tunis" },
    type: string
  }
];

string
实际上不是列类型的可接受类型:


我创建了一个PR来解决这个问题,但是如果您正在显示一个字符串,您可以省略该类型。

使用原始字符串值
字符串
将被解释为类型不正确的字符串。 要解决此问题,请将其强制转换为
const

columns = [...{
    title: "Birth Place",
    field: "birthCity",
    type: "string" as const // ERROR ?!
}]
columns = [...{
    title: "Birth Place",
    field: "birthCity",
    type: "string" as const // ERROR ?!
}]