经过大量的搜索后,尽管ag-grid-react项目似乎具有打字稿键入功能,但我仍然找不到使用ag-grid-react和打字稿的示例。
在我的react应用中,我已经安装了ag-grid-react:npm i --save ag-grid ag-grid-react react-dom-factories
此代码作为jsx文件看起来不错,但是如果我尝试将其用作打字稿tsx文件,则会出现编译器错误:
const columnDefs = [
{headerName: 'Make', field: 'make'},
{headerName: 'Model', field: 'model'},
{headerName: 'Price', field: 'price'}
];
const rowData = [
{make: 'Toyota', model: 'Celica', price: 35000},
{make: 'Ford', model: 'Mondeo', price: 32000},
{make: 'Porsche', model: 'Boxter', price: 72000}
]
class App extends Component {
constructor(props: any) {
super(props);
}
render() {
return (
<div
className="ag-theme-balham"
style={{ height: '200px', width: '600px' }}
>
<AgGridReact
columnDefs={columnDefs}
rowData={rowData}>
</AgGridReact>
</div>
);
}
}
export default App;
AgGridReact标记上的编译错误
Type '{ children: never[]; columnDefs: { headerName: string; field:
string; }[]; rowData: { make: string; model: string; price: number;
}[]; }' is not assignable to type 'IntrinsicAttributes &
IntrinsicClassAttributes<AgGridReact> & Readonly<AgGridReactProps> &
Readonly<{ children?: ReactNode; }>'. Property 'columnDefs' does not
exist on type 'IntrinsicAttributes &
IntrinsicClassAttributes<AgGridReact> & Readonly<AgGridReactProps> &
Readonly<{ children?: ReactNode; }>'.ts(2322)
任何人都可以提供的指导吗?
答案 0 :(得分:0)
错误警报:我只需要npm install ag-grid-community
,而不是ag-grid