TS question with CalendarState | RangeCalendarState in CalendarCell.tsx #4017
Replies: 3 comments
-
I've gone with the solution of just casting it prior to these checks, but interested if anyone has any better solutions.
|
Beta Was this translation helpful? Give feedback.
-
I have the same issue. Although, not sure how you casted without TS issues: Edit: This is what I did const rangeState = state as unknown as RangeCalendarState;
const isSelectionStart = rangeState.highlightedRange
? isSameDay(date, rangeState.highlightedRange.start)
: isSelected;
const isSelectionEnd = rangeState.highlightedRange
? isSameDay(date, rangeState.highlightedRange.end)
: isSelected; |
Beta Was this translation helpful? Give feedback.
-
You could use const isSelectionStart = 'highlightedRange' in state
? isSameDay(date, state.highlightedRange.start)
: isSelected; |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have created a reusable Calendar that can be used for a single Calendar and a Range Calendar.
In my
CalendarCell.tsx
file I have defined state as a union:This is causing an issue because I am doing some conditional styling for the RangeCalendar which I saw in one of Styled Examples:
I get a TS error on
highlightedRange
because this only exists onRangeCalendarState
and notCalendarState
. I'm a TS newbie and don't know how to write this in such a way that I can almost do a TSif
check ortypeof
check first so that it knows whetherhighlightedRange
will be an available bit of state.If anyone has any ideas how I could achieve this that would be much appreciated = )
Beta Was this translation helpful? Give feedback.
All reactions