Skip to content

Commit d47fd29

Browse files
committed
Fix isValueOrValueArray propType not working well with TypeScript
1 parent e255387 commit d47fd29

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Calendar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
isMinDate,
1717
isRef,
1818
isView,
19+
rangeOf,
1920
} from './shared/propTypes';
2021
import { between } from './shared/utils';
2122

@@ -308,7 +309,7 @@ const isActiveStartDate = PropTypes.instanceOf(Date);
308309

309310
const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]);
310311

311-
const isValueOrValueArray = PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]);
312+
const isValueOrValueArray = PropTypes.oneOfType([isValue, rangeOf(isValue)]);
312313

313314
export default class Calendar extends Component<CalendarProps, CalendarState> {
314315
static defaultProps = defaultProps;

src/shared/propTypes.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import { CALENDAR_TYPES } from './const';
44

55
import type { Requireable, Validator } from 'prop-types';
6-
import type { View } from './types';
6+
import type { Range, View } from './types';
77

88
const calendarTypes = Object.values(CALENDAR_TYPES);
99
const allViews = ['century', 'decade', 'year', 'month'];
@@ -118,6 +118,10 @@ isView.isRequired = function isViewIsRequired(
118118
return isView(props, propName, componentName, location, propFullName);
119119
};
120120

121+
export const rangeOf = <T>(type: Requireable<T>): Requireable<Range<T>> => {
122+
return PropTypes.arrayOf(type) as Requireable<Range<T>>;
123+
};
124+
121125
export const tileGroupProps = {
122126
activeStartDate: PropTypes.instanceOf(Date).isRequired,
123127
hover: PropTypes.instanceOf(Date),

0 commit comments

Comments
 (0)