是否可以使用 typescript 扩展 react table v8 API

问题描述 投票:0回答:1

我正在尝试使用自定义函数扩展 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”隐式具有“任何”类型。

reactjs typescript extend react-table
1个回答
0
投票

你需要导入

import "@tanstack/react-table";

import "@tanstack/react-table";

declare module '@tanstack/table-core' {
  interface Table<TData extends RowData> {
    someCustomFunction: () => boolean;
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.