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 38c02a4 commit 5debea6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/DateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion src/shared/propTypes.ts
Original file line number Diff line number Diff line change
@@ -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<Date | null | undefined> = function isMinDate(
props,
Expand Down Expand Up @@ -55,3 +58,7 @@ export const isMaxDate: Validator<Date | null | undefined> = function isMaxDate(

return null;
};

export const rangeOf = <T>(type: Requireable<T>): Requireable<Range<T>> => {
return PropTypes.arrayOf(type) as Requireable<Range<T>>;
};
2 changes: 1 addition & 1 deletion src/shared/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Range<T> = [T, T];
export type Range<T> = [T, T];

export type ClassName = string | null | undefined | (string | null | undefined)[];

Expand Down

0 comments on commit 5debea6

Please sign in to comment.