Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Table] 扩展PrimaryTableCol类型带来的报错 #5076

Open
atox996 opened this issue Feb 24, 2025 · 5 comments
Open

[Table] 扩展PrimaryTableCol类型带来的报错 #5076

atox996 opened this issue Feb 24, 2025 · 5 comments

Comments

@atox996
Copy link

atox996 commented Feb 24, 2025

tdesign-vue-next 版本

1.10.7

重现链接

No response

重现步骤

<template>
  <t-table
      :columns="columns"
    >
    </t-table>
</template>

<script lang="ts" setup>
import type { PrimaryTableCol } from "tdesign-vue-next";

interface Data {
  id: string;
  name: string;
}

const columns: PrimaryTableCol<Data>[] = [
  {
    colKey: "id",
    title: "ID",
  },
  {
    colKey: "name",
    title: "名称",
    cell(h, { row }) {
      return row.name || "- -";
    }
  }
];
</script>

报错信息:
参数“props”和“props” 的类型不兼容。
不能将类型“PrimaryTableCellParams”分配给类型“PrimaryTableCellParams”。
属性“row”的类型不兼容。
类型“TableRowData”与类型“Data”不具有相同的属性。ts-plugin(2322)

期望结果

No response

实际结果

No response

框架版本

No response

浏览器版本

No response

系统版本

No response

Node版本

No response

补充说明

No response

Copy link
Contributor

👋 @atox996,感谢给 TDesign 提出了 issue。
请根据 issue 模版确保背景信息的完善,我们将调查并尽快回复你。

@atox996
Copy link
Author

atox996 commented Feb 24, 2025

加上默认的TableRowData联合类型可以解决

const columns: PrimaryTableCol<Data & TableRowData>[] = [
  {
    colKey: "id",
    title: "ID",
  },
  {
    colKey: "name",
    title: "名称",
    cell(h, { row }) {
      return row.name || "- -";
    }
  }
];

@atox996 atox996 closed this as completed Feb 24, 2025
@atox996 atox996 reopened this Mar 5, 2025
@atox996
Copy link
Author

atox996 commented Mar 5, 2025

依然报错~,希望能帮忙提供解决方案

 参数“props”和“props” 的类型不兼容。
              不能将类型“PrimaryTableCellParams<TableRowData>”分配给类型“PrimaryTableCellParams<{ id: string; name: string; } & TableRowData>”。
                属性“row”的类型不兼容。
                  不能将类型“TableRowData”分配给类型“{ id: string; name: string; } & TableRowData”。
                    类型“TableRowData”缺少类型“{ id: string; name: string; }”中的以下属性: id, name ts-plugin(2322)

@atox996
Copy link
Author

atox996 commented Mar 5, 2025

如果我将类型改为这样,就不会报错了, Data必须是可选类型

const columns: PrimaryTableCol<Partial<Data> & TableRowData>[] = [
  {
    colKey: "id",
    title: "ID",
  },
  {
    colKey: "name",
    title: "名称",
    cell(h, { row }) {
      return row.name || "- -";
    }
  }
];

@atox996
Copy link
Author

atox996 commented Mar 5, 2025

如果我将类型改为这样,就不会报错了, Data必须是可选类型

const columns: PrimaryTableCol<Partial & TableRowData>[] = [
{
colKey: "id",
title: "ID",
},
{
colKey: "name",
title: "名称",
cell(h, { row }) {
return row.name || "- -";
}
}
];

所以我认为,仓库中的

export interface TableRowData {
    [key: string]: any;
    children?: TableRowData[];
}

应该改为

export interface TableRowData {
    [key: string]?: any;
    children?: TableRowData[];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant