You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Using a datepicker with selectsRange in TypeScript, the onChange event show a Type error as below: Type '(date: Date | null, event: SyntheticEvent<any, Event> | undefined) => void' is not assignable to type '(date: [Date | null, Date | null], event: SyntheticEvent<any, Event> | undefined) => void'.ts(2769)
Although in the ReactDatePickerProps from index.d.ts there is a typing for onChange, it seems to not be working correctly with the prop WithRange. onChange( date: WithRange extends false | undefined ? (WithMultiple extends false | undefined ? Date | null : Date[] | null) : [Date | null, Date | null], event: React.SyntheticEvent<any> | undefined, ): void;
To Reproduce
Steps to reproduce the behavior:
1 - Create a datepicker that receives a onChange event with the props extending from ReactDatePickerProps.
2 - Add the onChange property to it
3 - Add the selectsRange property to it
4 - See the error.
Expected behavior
It should identify that the event is correctly typed.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
OS: [Windows 11]
Browser [None]
Version [6.2.0]
Additional context
In this case I'm trying to use the component on a Form and pass the onChange as a prop. But didn't find a way to fix the typing error without messing with the "index.d.ts" file.
The text was updated successfully, but these errors were encountered:
Lukaoxp
changed the title
Datepicker onChange event typing Error when selectsRange prop is true
Datepicker onChange event type Error when selectsRange prop is true
May 6, 2024
Describe the bug
Using a datepicker with selectsRange in TypeScript, the onChange event show a Type error as below:
Type '(date: Date | null, event: SyntheticEvent<any, Event> | undefined) => void' is not assignable to type '(date: [Date | null, Date | null], event: SyntheticEvent<any, Event> | undefined) => void'.ts(2769)
Although in the ReactDatePickerProps from index.d.ts there is a typing for onChange, it seems to not be working correctly with the prop WithRange.
onChange( date: WithRange extends false | undefined ? (WithMultiple extends false | undefined ? Date | null : Date[] | null) : [Date | null, Date | null], event: React.SyntheticEvent<any> | undefined, ): void;
To Reproduce
Steps to reproduce the behavior:
1 - Create a datepicker that receives a onChange event with the props extending from ReactDatePickerProps.
2 - Add the onChange property to it
3 - Add the selectsRange property to it
4 - See the error.
Here is my code:
Expected behavior
It should identify that the event is correctly typed.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
In this case I'm trying to use the component on a Form and pass the onChange as a prop. But didn't find a way to fix the typing error without messing with the "index.d.ts" file.
The text was updated successfully, but these errors were encountered: