Skip to content

Commit

Permalink
Fix isValueOrValueArray propType not working well with TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed May 28, 2023
1 parent e255387 commit d47fd29
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
isMinDate,
isRef,
isView,
rangeOf,
} from './shared/propTypes';
import { between } from './shared/utils';

Expand Down Expand Up @@ -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<CalendarProps, CalendarState> {
static defaultProps = defaultProps;
Expand Down
6 changes: 5 additions & 1 deletion src/shared/propTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -118,6 +118,10 @@ isView.isRequired = function isViewIsRequired(
return isView(props, propName, componentName, location, propFullName);
};

export const rangeOf = <T>(type: Requireable<T>): Requireable<Range<T>> => {
return PropTypes.arrayOf(type) as Requireable<Range<T>>;
};

export const tileGroupProps = {
activeStartDate: PropTypes.instanceOf(Date).isRequired,
hover: PropTypes.instanceOf(Date),
Expand Down

0 comments on commit d47fd29

Please sign in to comment.