范围选择器 onChange 日期参数的类型定义
Type definition of RangePicker onChange date paramater
根据文档 ant design 4.7
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[]'.
代码
const dateTimeOnChange = (
date: Array<Moment>,
dateString: Array<string>
): void => {
console.log(date);
console.log(dateString);
};
找不到 RangePicker onChange 第一个参数类型的类型定义和设计。
从错误消息和文档来看,问题很清楚。参数不是任意长度的数组,而是固定大小的数组(又名元组),date
参数也可以是 null
尝试
const dateTimeOnChange = (
date: [Moment, Moment] | null,
dateString: [string, string]
): void => {
console.log(date);
console.log(dateString);
};
如果 RangeValue
从声明它的模块中导出,您也可以使用 date: RangeValue<Moment>
。
根据文档 ant design 4.7
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[]'.
代码
const dateTimeOnChange = (
date: Array<Moment>,
dateString: Array<string>
): void => {
console.log(date);
console.log(dateString);
};
找不到 RangePicker onChange 第一个参数类型的类型定义和设计。
从错误消息和文档来看,问题很清楚。参数不是任意长度的数组,而是固定大小的数组(又名元组),date
参数也可以是 null
尝试
const dateTimeOnChange = (
date: [Moment, Moment] | null,
dateString: [string, string]
): void => {
console.log(date);
console.log(dateString);
};
如果 RangeValue
从声明它的模块中导出,您也可以使用 date: RangeValue<Moment>
。