diff --git a/src/DateRangePicker.tsx b/src/DateRangePicker.tsx index eca10fd7..a4048045 100644 --- a/src/DateRangePicker.tsx +++ b/src/DateRangePicker.tsx @@ -8,7 +8,7 @@ import Fit from 'react-fit'; import DateInput from 'react-date-picker/dist/cjs/DateInput'; -import { isMaxDate, isMinDate } from './shared/propTypes'; +import { isMaxDate, isMinDate, rangeOf } from './shared/propTypes'; import type { ClassName, CloseReason, Detail, LooseValue, OpenReason, Value } from './shared/types'; @@ -454,7 +454,7 @@ export default function DateRangePicker(props: DateRangePickerProps) { const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]); -const isValueOrValueArray = PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]); +const isValueOrValueArray = PropTypes.oneOfType([isValue, rangeOf(isValue)]); DateRangePicker.propTypes = { autoFocus: PropTypes.bool, diff --git a/src/shared/propTypes.ts b/src/shared/propTypes.ts index 8ff43a6d..3a2f8926 100644 --- a/src/shared/propTypes.ts +++ b/src/shared/propTypes.ts @@ -1,4 +1,7 @@ -import type { Validator } from 'prop-types'; +import PropTypes from 'prop-types'; + +import type { Requireable, Validator } from 'prop-types'; +import type { Range } from './types'; export const isMinDate: Validator = function isMinDate( props, @@ -55,3 +58,7 @@ export const isMaxDate: Validator = function isMaxDate( return null; }; + +export const rangeOf = (type: Requireable): Requireable> => { + return PropTypes.arrayOf(type) as Requireable>; +}; diff --git a/src/shared/types.ts b/src/shared/types.ts index 2e1f5d98..f06c8547 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -1,4 +1,4 @@ -type Range = [T, T]; +export type Range = [T, T]; export type ClassName = string | null | undefined | (string | null | undefined)[];