@@ -66,7 +66,7 @@ const defaultProps = {
6666 showNeighboringMonth : true ,
6767} ;
6868
69- type CalendarProps = typeof defaultProps & {
69+ type CalendarProps = {
7070 activeStartDate ?: Date ;
7171 allowPartialRange ?: boolean ;
7272 calendarType ?: CalendarType ;
@@ -123,6 +123,8 @@ type CalendarProps = typeof defaultProps & {
123123 view ?: View ;
124124} ;
125125
126+ type CalendarPropsWithDefaults = typeof defaultProps & CalendarProps ;
127+
126128type CalendarState = {
127129 action ?: Action ;
128130 activeStartDate ?: Date | null ;
@@ -256,7 +258,7 @@ function getActiveStartDate(
256258 return getBegin ( rangeType , valueFrom ) ;
257259}
258260
259- function getInitialActiveStartDate ( props : CalendarProps ) {
261+ function getInitialActiveStartDate ( props : CalendarPropsWithDefaults ) {
260262 const {
261263 activeStartDate,
262264 defaultActiveStartDate,
@@ -370,14 +372,18 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
370372 } ;
371373
372374 get activeStartDate ( ) {
373- const { activeStartDate : activeStartDateProps } = this . props ;
375+ const { activeStartDate : activeStartDateProps } = this . props as CalendarPropsWithDefaults ;
374376 const { activeStartDate : activeStartDateState } = this . state ;
375377
376- return activeStartDateProps || activeStartDateState || getInitialActiveStartDate ( this . props ) ;
378+ return (
379+ activeStartDateProps ||
380+ activeStartDateState ||
381+ getInitialActiveStartDate ( this . props as CalendarPropsWithDefaults )
382+ ) ;
377383 }
378384
379385 get value ( ) : Value {
380- const { selectRange, value : valueProps } = this . props ;
386+ const { selectRange, value : valueProps } = this . props as CalendarPropsWithDefaults ;
381387 const { value : valueState } = this . state ;
382388
383389 const rawValue = ( ( ) => {
@@ -401,26 +407,26 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
401407 }
402408
403409 get valueType ( ) {
404- const { maxDetail } = this . props ;
410+ const { maxDetail } = this . props as CalendarPropsWithDefaults ;
405411
406412 return getValueType ( maxDetail ) ;
407413 }
408414
409415 get view ( ) {
410- const { minDetail, maxDetail, view : viewProps } = this . props ;
416+ const { minDetail, maxDetail, view : viewProps } = this . props as CalendarPropsWithDefaults ;
411417 const { view : viewState } = this . state ;
412418
413419 return getView ( viewProps || viewState , minDetail , maxDetail ) ;
414420 }
415421
416422 get views ( ) {
417- const { minDetail, maxDetail } = this . props ;
423+ const { minDetail, maxDetail } = this . props as CalendarPropsWithDefaults ;
418424
419425 return getLimitedViews ( minDetail , maxDetail ) ;
420426 }
421427
422428 get hover ( ) {
423- const { selectRange } = this . props ;
429+ const { selectRange } = this . props as CalendarPropsWithDefaults ;
424430 const { hover } = this . state ;
425431
426432 return selectRange ? hover : null ;
@@ -442,7 +448,7 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
442448 * Gets current value in a desired format.
443449 */
444450 getProcessedValue ( value : Date ) {
445- const { minDate, maxDate, maxDetail, returnValue } = this . props ;
451+ const { minDate, maxDate, maxDetail, returnValue } = this . props as CalendarPropsWithDefaults ;
446452
447453 const processFunction = ( ( ) => {
448454 switch ( returnValue ) {
@@ -477,8 +483,8 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
477483 ) => {
478484 const { activeStartDate : previousActiveStartDate , view : previousView } = this ;
479485
480- const { allowPartialRange, onActiveStartDateChange, onChange, onViewChange, selectRange } =
481- this . props ;
486+ const { allowPartialRange, onActiveStartDateChange, onChange, onViewChange, selectRange } = this
487+ . props as CalendarPropsWithDefaults ;
482488
483489 const prevArgs = {
484490 action : undefined ,
@@ -571,7 +577,7 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
571577 this . onClickTile ( nextActiveStartDate , event ) ;
572578
573579 const { view, views } = this ;
574- const { onDrillDown } = this . props ;
580+ const { onDrillDown } = this . props as CalendarPropsWithDefaults ;
575581
576582 const nextView = views [ views . indexOf ( view ) + 1 ] ;
577583
@@ -596,7 +602,7 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
596602 }
597603
598604 const { activeStartDate, view, views } = this ;
599- const { onDrillUp } = this . props ;
605+ const { onDrillUp } = this . props as CalendarPropsWithDefaults ;
600606
601607 const nextView = views [ views . indexOf ( view ) - 1 ] ;
602608
@@ -619,7 +625,7 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
619625
620626 onChange = ( value : Date , event : React . MouseEvent < HTMLButtonElement > ) => {
621627 const { value : previousValue } = this ;
622- const { goToRangeStartOnSelect, selectRange } = this . props ;
628+ const { goToRangeStartOnSelect, selectRange } = this . props as CalendarPropsWithDefaults ;
623629
624630 this . onClickTile ( value , event ) ;
625631
@@ -659,7 +665,7 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
659665 // Range selection turned on, second value, goToRangeStartOnSelect toggled on
660666 goToRangeStartOnSelect
661667 ? getActiveStartDate ( {
662- ...this . props ,
668+ ...( this . props as CalendarPropsWithDefaults ) ,
663669 value : nextValue ,
664670 } )
665671 : null ;
@@ -678,7 +684,8 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
678684
679685 onClickTile = ( value : Date , event : React . MouseEvent < HTMLButtonElement > ) => {
680686 const { view } = this ;
681- const { onClickDay, onClickDecade, onClickMonth, onClickYear } = this . props ;
687+ const { onClickDay, onClickDecade, onClickMonth, onClickYear } = this
688+ . props as CalendarPropsWithDefaults ;
682689
683690 const callback = ( ( ) => {
684691 switch ( view ) {
@@ -723,7 +730,7 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
723730 tileClassName,
724731 tileContent,
725732 tileDisabled,
726- } = this . props ;
733+ } = this . props as CalendarPropsWithDefaults ;
727734 const { hover } = this ;
728735
729736 const activeStartDate = next
@@ -749,17 +756,17 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
749756
750757 switch ( view ) {
751758 case 'century' : {
752- const { formatYear } = this . props ;
759+ const { formatYear } = this . props as CalendarPropsWithDefaults ;
753760
754761 return < CenturyView formatYear = { formatYear } { ...commonProps } /> ;
755762 }
756763 case 'decade' : {
757- const { formatYear } = this . props ;
764+ const { formatYear } = this . props as CalendarPropsWithDefaults ;
758765
759766 return < DecadeView formatYear = { formatYear } { ...commonProps } /> ;
760767 }
761768 case 'year' : {
762- const { formatMonth, formatMonthYear } = this . props ;
769+ const { formatMonth, formatMonthYear } = this . props as CalendarPropsWithDefaults ;
763770
764771 return (
765772 < YearView formatMonth = { formatMonth } formatMonthYear = { formatMonthYear } { ...commonProps } />
@@ -776,7 +783,7 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
776783 showFixedNumberOfWeeks,
777784 showNeighboringMonth,
778785 showWeekNumbers,
779- } = this . props ;
786+ } = this . props as CalendarPropsWithDefaults ;
780787 const { onMouseLeave } = this ;
781788
782789 return (
@@ -805,7 +812,7 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
805812 }
806813
807814 renderNavigation ( ) {
808- const { showNavigation } = this . props ;
815+ const { showNavigation } = this . props as CalendarPropsWithDefaults ;
809816
810817 if ( ! showNavigation ) {
811818 return null ;
@@ -830,7 +837,7 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
830837 prevAriaLabel,
831838 prevLabel,
832839 showDoubleView,
833- } = this . props ;
840+ } = this . props as CalendarPropsWithDefaults ;
834841
835842 return (
836843 < Navigation
@@ -861,7 +868,8 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
861868 }
862869
863870 render ( ) {
864- const { className, inputRef, selectRange, showDoubleView } = this . props ;
871+ const { className, inputRef, selectRange, showDoubleView } = this
872+ . props as CalendarPropsWithDefaults ;
865873 const { onMouseLeave, value } = this ;
866874 const valueArray = Array . isArray ( value ) ? value : [ value ] ;
867875
0 commit comments