【问题标题】:Typescript ag-grid onGridReady params throws an errorTypescript ag-grid onGridReady 参数抛出错误
【发布时间】:2021-03-31 08:42:32
【问题描述】:

我正在使用带有 typescript 和 React 的 ag-grid

OnGridReady 事件参数抛出错误

import { AgGridEvent, ICellRendererParams, ModuleRegistry } from "@ag-grid-community/core";
  const onGridReady = (params: AgGridEvent): void => {
    setGridApi(params.api);
    params.api.sizeColumnsToFit();
  };

当我构建它时会引发错误

Type error: No overload matches this call.
  Overload 1 of 2, '(props: Readonly<AgGridReactProps>): AgGridReact', gave the following error.
    Type '(params: AgGridEvent) => void' is not assignable to type '(event: GridReadyEvent) => void'.
      Types of parameters 'params' and 'event' are incompatible.
        Type 'GridReadyEvent' is not assignable to type 'AgGridEvent'.
          Types of property 'api' are incompatible.
            Type 'import("/Users/subha/admin/admin_demo/node_modules/ag-grid-community/dist/lib/gridApi").GridApi' is not assignable to type 'import("/Users/subha/admin/admin_demo/node_modules/@ag-grid-community/core/dist/cjs/gridApi").GridApi'.
              Types have separate declarations of a private property 'immutableService'.
  Overload 2 of 2, '(props: AgGridReactProps, context?: any): AgGridReact', gave the following error.
    Type '(params: AgGridEvent) => void' is not assignable to type '(event: GridReadyEvent) => void'.
  104 |           suppressCellSelection={true}
  105 |           frameworkComponents={{ editRenderer }}
> 106 |           onGridReady={onGridReady}
      |           ^
  107 |         ></AgGridReact>
  108 |       </div>
  109 |     </div>
info  - Creating an optimized production build .npm ERR! code ELIFECYCLE**

【问题讨论】:

  • 当你尝试使用 AgGridEvent 类型 GridReadyEvent?

标签: reactjs typescript ag-grid


【解决方案1】:

正如@LiH 在上面的评论中提到的,我正在使用GridReadyEvent,它工作正常。所以你的情况是:

import { GridReadyEvent, ICellRendererParams, ModuleRegistry } from "@ag-grid-community/core";
  const onGridReady = (params: GridReadyEvent): void => {
    setGridApi(params.api);
    params.api.sizeColumnsToFit();
  };

【讨论】:

    猜你喜欢
    • 2019-09-18
    • 2018-09-29
    • 2023-03-03
    • 2020-06-20
    • 2020-11-06
    • 2016-11-04
    • 2021-01-15
    • 2017-01-22
    • 1970-01-01
    相关资源
    最近更新 更多