问题描述
根据文档ant design 4.7
<table id="Table1">
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
onChange Callback function,can be executed when the selected time is changing function(dates: [moment,moment],dateStrings: [string,string])
Type '(date: Array<Moment>,dateString: Array<string>) => void' is not assignable to type '(values: RangeValue<Moment>,formatString: [string,string]) => void'.
Types of parameters 'date' and 'values' are incompatible.
Type 'RangeValue<Moment>' is not assignable to type 'Moment[]'.
Type 'null' is not assignable to type 'Moment[]'.
找不到类型定义,无法设计RangePicker onChange 1st参数类型。
解决方法
从错误消息和文档中,问题很明显。参数不是任意长度的数组,而是固定大小的数组(也称为元组),date
参数也可以是null
尝试
const dateTimeOnChange = (
date: [Moment,Moment] | null,dateString: [string,string]
): void => {
console.log(date);
console.log(dateString);
};
如果date: RangeValue<Moment>
是从声明它的模块中导出的,则也可以使用RangeValue
。