为什么react-day-picker onDayClick给出No overload匹配这个调用错误?



我是React的新手,我正在尝试使用[React -day-picker][1]作为一个简单的日期选择选项。问题是我复制了代码,因为他们在[示例][2],但onDayPick参数有一个弯曲的线,给了我这个错误

No overload matches this call.
Overload 1 of 2, '(props: DayPickerProps | Readonly<DayPickerProps>): DayPicker', gave the following error.
Type '(day: any, { selected, disabled }: { selected: any; disabled: any; }) => void' is not assignable to type '(day: Date, modifiers: DayModifiers, e: MouseEvent<HTMLDivElement, MouseEvent>) => void'.
Types of parameters '__1' and 'modifiers' are incompatible.
Type 'DayModifiers' is missing the following properties from type '{ selected: any; disabled: any; }': selected, disabled
Overload 2 of 2, '(props: DayPickerProps, context: any): DayPicker', gave the following error.
Type '(day: any, { selected, disabled }: { selected: any; disabled: any; }) => void' is not assignable to type '(day: Date, modifiers: DayModifiers, e: MouseEvent<HTMLDivElement, MouseEvent>) => void'.

这是我的组件,以防我在复制它时做错了什么

import React from 'react';
import DayPicker from 'react-day-picker';
import 'react-day-picker/lib/style.css';

export default class DatePicker extends React.Component<{}, {selectedDay: any}>{
constructor(props) {
super(props);
this.state = {
selectedDay: undefined,
}
this.handleDayClick = this.handleDayClick.bind(this);
}
handleDayClick(day, { selected, disabled }) {
if (disabled) {
// Day is disabled, do nothing
return;
}
if (selected) {
// Unselect the day if already selected
this.setState({ selectedDay: undefined });
return;
}
this.setState({ selectedDay: day });
}
render() {
return(
<div>
<DayPicker
onDayClick={this.handleDayClick}
selectedDays={this.state.selectedDay}
/>
{this.state.selectedDay ? (
<p>You clicked {this.state.selectedDay.toLocaleDateString()}</p>
) : (
<p>Please select a day.</p>
)}
</div>
)
}
}
[1]: https://react-day-picker.js.org/
[2]: https://react-day-picker.js.org/docs/basic-concepts

它适用于我在chrome与一个基本的反应应用程序。我在package.json中使用这些版本:

"react": "^17.0.1",
"react-day-picker": "^7.4.8",
"react-dom": "^17.0.1",

最新更新