In my current project, I am working on a Nextjs
application that utilizes typescript
and antd
.
The application includes a table component from antd
which allows users to select rows.
const rowSelection = {
onChange: (selectedKeys: any[], selectedRows: Mission[]) => {
console.log(selectedKeys);
}
}
The output shows: [12, 11, 10]
This is an array of numbers.
However, when I change it to selectedKeys: number[]
:
Type '{ onChange: (selectedKeys: number[], selectedRows: Mission[]) => void; getCheckboxProps: (record: Mission) => { disabled: boolean; }; }' is not assignable to type 'TableRowSelection<Mission>'.
Types of property 'onChange' are incompatible.
Type '(selectedKeys: number[], selectedRows: Mission[]) => void' is not assignable to type '(selectedRowKeys: Key[], selectedRows: Mission[], info: { type: RowSelectMethod; }) => void'.
Types of parameters 'selectedKeys' and 'selectedRowKeys' are incompatible.
Type 'Key[]' is not assignable to type 'number[]'.
Type 'Key' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.ts(2322)
Table.d.ts(22, 5): The expected type comes from property 'rowSelection' which is declared here on type 'IntrinsicAttributes & TableProps<Mission> & { children?: ReactNode; } & { ref?: Ref<HTMLDivElement> | undefined; }'
Why is this happening?