-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Describe the bug
I am using typescript in my project and I am trying to create a reusable DatePicker component with ability to display range datepicker or simple datepicker (with one date) depend on passing such props as selectsRange, startDate, endDate. But typescript doesn't allow me to do that, it throws such errors:
- Type 'Date' is not assignable to type '[Date, Date]' for the range variant
- Type '[Date, Date]' is not assignable to type Date for a simple datepicker
To Reproduce
Try to set such type check for the datepicker wrapper component: onChange: (date: Date | [Date, Date] | null, event: React.SyntheticEvent) => void, and then use onChange on the instance component.
Expected behavior
It should allow conditionally create 2 variants of datepicker (it is possible with clean jsx)
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
Additional context
Add any other context about the problem here.