我正在尝试使用自定义函数扩展 react-table v8 api。
在文档中说可以:
declare module '@tanstack/table-core' {
interface TableMeta<TData extends RowData> {
someCustomFunction: () => boolean;
}
}
之后我们可以访问这个函数:
table.options.meta.someCustomFunction()
我正在寻找一种方法来扩展
table
本身。
table.someCustomFunction()
但是当我尝试
declare module '@tanstack/table-core' {
interface Table<TData extends RowData> {
someCustomFunction: () => boolean;
}
}
打字稿抱怨:
{headerGroup.headers.map((header) => {...
参数“header”隐式具有“任何”类型。
{table.getHeaderGroups().map((headerGroup) => (....
参数“headerGroup”隐式具有“任何”类型。
你需要导入
import "@tanstack/react-table";
import "@tanstack/react-table";
declare module '@tanstack/table-core' {
interface Table<TData extends RowData> {
someCustomFunction: () => boolean;
}
}