I want to update handleChange event as 'CalendarChangeParams', not as 'any', when I do so, I cannot update state which keeps values of picked dates.
When I hover over below marked fields:
Typescript throws me error as below:
const newValues: Date | Date[] Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'Date | Date[]'. Property '0' does not exist on type 'Date | Date[]'.ts(7053)
I cannot figure out what is wrong here as event is actually an array with Date
type OnChangeType = {
startDate: Date;
endDate: Date;
};
type CalendarProps = {
startDate: Date;
endDate: Date;
onChange: ({ startDate, endDate }: OnChangeType) => void;
} & CalendarComponentProps;
export const Calendar: FC<CalendarProps> = (props) => {
const { selectionMode, onChange, startDate, endDate, ...rest } = props;
const [values, setValues] = useState<Date | Date[] | undefined>([startDate, endDate]);
const handleChange = (e: CalendarChangeParams) => {
const newValues = e.value;
if (!newValues) return;
setValues(newValues);
onChange({
startDate: newValues[0],
endDate: newValues[1],
});
};
thanks