From d47fd2926e5cc4383ba5f9a7cb87f334f113fe56 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Sun, 28 May 2023 15:15:01 +0200 Subject: [PATCH] Fix isValueOrValueArray propType not working well with TypeScript --- src/Calendar.tsx | 3 ++- src/shared/propTypes.ts | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Calendar.tsx b/src/Calendar.tsx index 99dc562b..056815fd 100644 --- a/src/Calendar.tsx +++ b/src/Calendar.tsx @@ -16,6 +16,7 @@ import { isMinDate, isRef, isView, + rangeOf, } from './shared/propTypes'; import { between } from './shared/utils'; @@ -308,7 +309,7 @@ const isActiveStartDate = PropTypes.instanceOf(Date); const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]); -const isValueOrValueArray = PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]); +const isValueOrValueArray = PropTypes.oneOfType([isValue, rangeOf(isValue)]); export default class Calendar extends Component { static defaultProps = defaultProps; diff --git a/src/shared/propTypes.ts b/src/shared/propTypes.ts index 026ff2a5..eaaa1120 100644 --- a/src/shared/propTypes.ts +++ b/src/shared/propTypes.ts @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { CALENDAR_TYPES } from './const'; import type { Requireable, Validator } from 'prop-types'; -import type { View } from './types'; +import type { Range, View } from './types'; const calendarTypes = Object.values(CALENDAR_TYPES); const allViews = ['century', 'decade', 'year', 'month']; @@ -118,6 +118,10 @@ isView.isRequired = function isViewIsRequired( return isView(props, propName, componentName, location, propFullName); }; +export const rangeOf = (type: Requireable): Requireable> => { + return PropTypes.arrayOf(type) as Requireable>; +}; + export const tileGroupProps = { activeStartDate: PropTypes.instanceOf(Date).isRequired, hover: PropTypes.instanceOf(Date),