【发布时间】: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