2

I am using ag-grid with typescript and React

OnGridReady event params throws an error

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

When I build it throws an error

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**
1
  • 1
    When you try use instead AgGridEvent type GridReadyEvent? Commented Dec 21, 2020 at 15:18

1 Answer 1

1

As mentioned by @LiH in the comment above, I am using GridReadyEvent and it is working fine. So in your case it would be:

import { GridReadyEvent, ICellRendererParams, ModuleRegistry } from "@ag-grid-community/core";
  const onGridReady = (params: GridReadyEvent): void => {
    setGridApi(params.api);
    params.api.sizeColumnsToFit();
  };
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.